- val = digitalRead(switchPin); // read input value and store it in val
- delay(100); // Debounce
- if ((val != buttonState) && (val == HIGH)) { // check if the button is pressed
+ statoAttuale = digitalRead(switchPin); // read input value and store it in val
+ delay(20); // Debounce, sort of...
+ if ((statoAttuale != ultimoStato) && (statoAttuale == HIGH)) { // check if the button is pressed