1 /* Blink con state machine
3 Accendere e spegnere un led utilizzando una state machine
4 specificando sia il tempo accensione che di spegnimento.
8 // These variables store the flash pattern
9 // and the current state of the LED
11 int ledPin = 13; // the number of the LED pin
12 int ledState = LOW; // ledState used to set the LED
13 unsigned long previousMillis = 0; // will store last time LED was updated
14 long intervalHigh = 1000; //
15 long intervalLow = 200; //
19 // set the digital pin as output:
20 pinMode(ledPin, OUTPUT);
25 // check to see if it's time to change the state of the LED
26 unsigned long currentMillis = millis();
27 if((ledState == HIGH) && (currentMillis - previousMillis >= intervalHigh))
29 ledState = !ledState ; // Inverti il LED
30 previousMillis = currentMillis; // Remember the time
31 digitalWrite(ledPin, ledState); // Update the actual LED
34 else if((ledState == LOW) && (currentMillis - previousMillis >= intervalLow))
36 ledState = !ledState ; // Inverti il LED
37 previousMillis = currentMillis; // Remember the time
38 digitalWrite(ledPin, ledState); // Update the actual LED
45 1. Modificare il codice in modo che si possa precisare il tempo di HIGH
47 2. Aggiungere un LED che brilli ogni 500ms