5 3. Provare a isolare il codice per accendere ogni singolo led in una funzione:
6 Quali variabili determinano il comportamento del LED?
11 // constants won't change. Used here to
15 const int ledA = 13; // the number of the LED pin
17 // Variables will change:
18 int ledStateA = LOW; // ledState used to set the LED
20 long previousMillisA = 0; // will store last time LED was updated
22 // the follow variables is a long because the time, measured in miliseconds,
23 // will quickly become a bigger number than can be stored in an int.
24 long intervalA = 1000; // interval at which to blink (milliseconds)
27 int ledB = 12; //Secondo LED
28 int ledStateB = LOW; // ledState used to set the LED
29 long previousMillisB = 0; // will store last time LED was updated
30 long intervalB = 500; // interval at which to blink (milliseconds)
34 // set the digital pin as output:
35 pinMode(ledA, OUTPUT);
36 pinMode(ledB, OUTPUT);
49 if(millis() - previousMillisA > intervalA) {
50 // save the last time you blinked the LED
51 previousMillisA = millis();
53 // if the LED is off turn it on and vice-versa:
58 // set the LED with the ledState of the variable:
59 digitalWrite(ledA, ledStateA);
65 if(millis() - previousMillisB > intervalB) {
66 // save the last time you blinked the LED
67 previousMillisB = millis();
69 // if the LED is off turn it on and vice-versa:
74 // set the LED with the ledState of the variable:
75 digitalWrite(ledB, ledStateB);
81 2. Inserire un secondo LED con intervallo 500ms
82 1. Trasformare il codice utilizzato in una State Machine