int buttonPresses = 0; // Counter for the button
void setup() {
- pinMode(switchPin, INPUT_PULLUP); // Set the switch pin as input
+ pinMode(switchPin, INPUT); // Set the switch pin as input
Serial.begin(9600); // Set up serial communication at 9600bps
ultimoStato = digitalRead(switchPin); // read the initial state
void loop(){
statoAttuale = digitalRead(switchPin); // read input value and store it in val
- delay(100); // Debounce, sort of...
+ delay(20); // Debounce, sort of...
if ((statoAttuale != ultimoStato) && (statoAttuale == HIGH)) { // check if the button is pressed
buttonPresses++ ;
Serial.print("Button has been pressed ");