5 Soluzione: Provare a isolare il codice per accendere ogni singolo led in una funzione:
7 - Quali variabili determinano il comportamento del LED?
8 - Come cambiano durante il corso dello script?
9 - Sono globali o locali?
15 int ledA = 13; // the number of the LED pin
16 // Variables will change:
17 int ledStateA = LOW; // ledState used to set the LED
18 long previousMillisA = 0; // will store last time LED was updated
19 // the follow variables is a long because the time, measured in miliseconds,
20 // will quickly become a bigger number than can be stored in an int.
21 long intervalA = 1000; // interval at which to blink (milliseconds)
25 int ledB = 12; //Secondo LED
26 // ledState used to set the LED
27 long previousMillisB = 0; // will store last time LED was updated
28 // interval at which to blink (milliseconds)
32 // set the digital pin as output:
33 pinMode(ledA, OUTPUT);
34 pinMode(ledB, OUTPUT);
47 if(millis() - previousMillisA > intervalA) {
48 // save the last time you blinked the LED
49 previousMillisA = millis();
51 // if the LED is off turn it on and vice-versa:
56 // set the LED with the ledState of the variable:
57 digitalWrite(ledA, ledStateA);
64 static int ledStateB ;
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 1. Modificare le funzioni in modo che accettino come parametro
82 l'intervallo di lampeggio.