int button_Minus = 8;
int button_Plus = 9;
int button_Select = 10;
float x;
float y=10;
float z=10;
bool buttonState1; // current state of the button
bool lastButtonState1; // previous state of the button
bool buttonState2; // current state of the button
bool lastButtonState2; // previous state of the button
bool buttonState3; // current state of the button
bool lastButtonState3; // previous state of the button
unsigned long prevmillis; // to replace delay(50)
unsigned long timeButtonSelectLOW; // to calculate 2 seconds
void setup() {
pinMode(button_Minus, INPUT_PULLUP);
pinMode(button_Plus, INPUT_PULLUP);
pinMode(button_Select,INPUT_PULLUP);
Serial.begin(115200); //
Serial.println(F("go ! press a button"));
}
void loop(){
unsigned long now = millis(); // to replace delay(50)
if (now - prevmillis > 20) { // 20 ms (instead of 50)
prevmillis = now;
// option 1
buttonState1 = digitalRead(button_Minus);
if (buttonState1 != lastButtonState1) {
lastButtonState1 = buttonState1;
if (buttonState1 == LOW) {
y=y-0.1;
Serial.println(F("button_Minus"));
}
}
// option 2
buttonState2 = digitalRead(button_Plus);
if (buttonState2 != lastButtonState2) {
lastButtonState2 = buttonState2;
if (buttonState2 == LOW) {
z=z+0.1;
Serial.println(F("button_Plus"));
}
}
// option 3
buttonState3 = digitalRead(button_Select);
if (buttonState3 != lastButtonState3) {
lastButtonState3 = buttonState3;
if (buttonState3 == LOW) {
Serial.println(F("button_Select"));
}
}
}
}