X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=basic%2Fbuttons%2Fbutton_state_3%2Fbutton_state_3.ino;h=7eee7e4a1df9a87ab3844038f2c03defbf23c130;hb=fa3554ca7f433786f4f65bd266f0a356a89bed0b;hp=2bc683b8a3bbd11eb90cf7a56ce9a79c680877a0;hpb=0807dd2a57e859d7fc246d8eb02692ea4d0da248;p=sketchbook_andrea diff --git a/basic/buttons/button_state_3/button_state_3.ino b/basic/buttons/button_state_3/button_state_3.ino index 2bc683b..7eee7e4 100644 --- a/basic/buttons/button_state_3/button_state_3.ino +++ b/basic/buttons/button_state_3/button_state_3.ino @@ -5,9 +5,11 @@ */ -int switchPin = 2; // switch is connected to pin 2 -int statoAttuale; // variable for reading the pin status -int ultimoStato; // variable to hold the last button state +int switchPin = 2; // switch connesso al pin 2 + // Nota: le prossime due variabili sono + // solo "dichiarate" e non "definite" +int statoAttuale; // Variabile per leggere lo stato del bottone +int ultimoStato; // Variabile per registrare l'ultimo stato del bottone void setup() { pinMode(switchPin, INPUT); // Set the switch pin as input @@ -18,10 +20,11 @@ void setup() { void loop(){ - statoAttuale = digitalRead(switchPin); // read input value and store it in val - // delay(20) // riduce leffetto bounce - if (statoAttuale != ultimoStato) { // the button state has changed! - if (statoAttuale == HIGH) { // check if the button is pressed + 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... @@ -29,6 +32,6 @@ void loop(){ } } - ultimoStato = statoAttuale; // save the new state in our variable + ultimoStato = statoAttuale; // Aggiorna lo stato finale al valore attuale }