]> git.piffa.net Git - sketchbook_andrea/blobdiff - basic/buttons/button_state_4_state_and_condition/button_state_4_state_and_condition.ino
operatori + analog
[sketchbook_andrea] / basic / buttons / button_state_4_state_and_condition / button_state_4_state_and_condition.ino
index 42fd3a05f82838fb705e564a14a41fd83261eeb5..3cbc8698f4e6c681bf19b20e22c57667e704ca64 100644 (file)
@@ -6,23 +6,23 @@
  */
 int led = 13;
 int buttonPin = 2;              
-int statoAttuale;                        // variable for reading the pin status
-int ultimoStato;                // variable to hold the last button state
+int statoAttuale;          // Variabile per leggere lo stato del bottone
+int ultimoStato;           // Variabile per registrare l'ultimo stato del bottone
 int ledStatus;             // varabile per mantenere lo stato del led
 
 void setup() {
   pinMode(buttonPin, INPUT);    // Set the switch pin as input
   pinMode(led, OUTPUT);    
-  Serial.begin(9600);           // Set up serial communication at 9600bps
-  ultimoStato = digitalRead(buttonPin);   // read the initial state
-  ledStatus = 0;
+  Serial.begin(9600);                 // Attiva la comunicazione seriale a 9600bps
+  ultimoStato = digitalRead(buttonPin);   // Prima lettura del bottone
+  ledStatus = 0;                          // Il LED viene inpostato come spento  
 }
 
 void loop(){
-  statoAttuale = digitalRead(buttonPin);      // read input value and store it in var
+  statoAttuale = digitalRead(buttonPin);      // Legge lo stato del bottone e lo resistra in val
   delay(20);                      // riduce l'effetto bounce
-  if (statoAttuale != ultimoStato && statoAttuale == HIGH) {         
-    // the button state has changed AND the button is pressed
+  if (statoAttuale != ultimoStato && statoAttuale == HIGH) { // due condizione contemporanee
+    // lo stato del bottone e' camabiato AND lo stato attuale e' HIGH
       Serial.println("Button premuto");
     
       ledStatus = !ledStatus ;    // Inverte lo stato del LED 
@@ -32,7 +32,7 @@ void loop(){
       Serial.println(ledStatus) ;
   }
 
-  ultimoStato = statoAttuale;                 // save the new state in our variable
+  ultimoStato = statoAttuale;        // Aggiorna lo stato finale al valore attuale
   digitalWrite(led, ledStatus);      // setta il led allo stato richiesto
 
 }