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=83b274f17b45fd68deedde388f5cefba211482cb;hpb=8bbff1c558947ca1ff1733240827c87494ff4fd5;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 83b274f..7eee7e4 100644 --- a/basic/buttons/button_state_3/button_state_3.ino +++ b/basic/buttons/button_state_3/button_state_3.ino @@ -6,6 +6,8 @@ */ 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 @@ -19,8 +21,9 @@ void setup() { void loop(){ statoAttuale = digitalRead(switchPin); // Legge lo stato del bottone e lo resistra in val - delay(20) // riduce l'effetto bounce - if (statoAttuale != ultimoStato) { // lo stato del bottone e' cambiato + 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"); }