4 Il programma rileva la pressione del bottone e
5 riduce un contatore ad ogni pressione,
6 passando dallo stato iniziale a un secondo stato finale
10 int switchPin = 2; // switch is connected to pin 2
11 int val; // variable for reading the pin status
12 int buttonState; // variable to hold the last button state
13 int buttonPresses = 10; // Counter for the button
16 pinMode(switchPin, INPUT_PULLUP); // Set the switch pin as input
18 Serial.begin(9600); // Set up serial communication at 9600bps
19 buttonState = digitalRead(switchPin); // read the initial state
20 Serial.println("Don not press the button! :P ");
25 val = digitalRead(switchPin); // read input value and store it in val
26 delay(100); // Debounce
27 if ((val != buttonState) && (val == HIGH)) { // check if the button is pressed
29 Serial.print("Press it an other ");
30 Serial.print(buttonPresses);
31 Serial.println(" times.");
33 if (buttonPresses == 0) {
34 Serial.println("----- > ExplOdE! <------");
35 // Serial.flush(); // Print out the whole serial buffer
36 // exit(0); // Exit the sketch
38 buttonState = val; // save the new state in our variable