- val = digitalRead(switchPin); // read input value and store it in val
-
- if (val != buttonState) { // the button state has changed!
- if (val == LOW) { // check if the button is pressed
- Serial.println("Button just pressed");
- } else { // the button is -not- pressed...
- Serial.println("Button just released");
+ statoAttuale = digitalRead(switchPin); // Legge lo stato del bottone e lo resistra in val
+ delay(20); // riduce l'effetto bounce
+ if (statoAttuale != ultimoStato) {
+ // verifica due condizioni che devono realizzarsi contemporaneamente
+ if (statoAttuale == HIGH) { // il bottone e' stato premuto
+ Serial.println("Bottone premuto");
+ }
+ else { // the button is -not- pressed...
+ Serial.println("Bottone rilasciato");