4 Legge lo stato di un input
8 int switchPin = 2; // switch is connected to pin 2
9 int statoAttuale; // variable for reading the pin status
10 int ultimoStato; // variable to hold the last button state
13 pinMode(switchPin, INPUT); // Set the switch pin as input
15 Serial.begin(9600); // Set up serial communication at 9600bps
16 ultimoStato = digitalRead(switchPin); // read the initial state
21 statoAttuale = digitalRead(switchPin); // read input value and store it in val
22 // delay(20) // riduce leffetto bounce
23 if (statoAttuale != ultimoStato) { // the button state has changed!
24 if (statoAttuale == HIGH) { // check if the button is pressed
25 Serial.println("Bottone premuto");
27 else { // the button is -not- pressed...
28 Serial.println("Bottone rilasciato");
32 ultimoStato = statoAttuale; // save the new state in our variable