1 /* Blink con state machine
3 Accendere e spegnere un led utilizzando una state machine
6 // These variables store the flash pattern
7 // and the current state of the LED
9 int ledPin = 13; // the number of the LED pin
10 int ledState = LOW; // ledState used to set the LED
11 unsigned long previousMillis = 0; // will store last time LED was updated
12 long interval = 1000; //
16 // set the digital pin as output:
17 pinMode(ledPin, OUTPUT);
22 // check to see if it's time to change the state of the LED
23 unsigned long currentMillis = millis();
24 if((ledState == HIGH) && (currentMillis - previousMillis >= interval))
26 ledState = !ledState ; // Inverti il LED
27 previousMillis = currentMillis; // Remember the time
28 digitalWrite(ledPin, ledState); // Update the actual LED
31 else if((ledState == LOW) && (currentMillis - previousMillis >= interval))
33 ledState = !ledState ; // Inverti il LED
34 previousMillis = currentMillis; // Remember the time
35 digitalWrite(ledPin, ledState); // Update the actual LED
42 1. Modificare il codice in modo che si possa precisare il tempo di HIGH
44 2. Aggiungere un LED che brilli ogni 500ms