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)
26 int ledB = 12; //Secondo LED
27 // ledState used to set the LED
28 long previousMillisB = 0; // will store last time LED was updated
29 // 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);
66 static int ledStateB ; // https://www.arduino.cc/en/Reference/Static
67 if(millis() - previousMillisB > intervalB) {
68 // save the last time you blinked the LED
69 previousMillisB = millis();
71 // if the LED is off turn it on and vice-versa:
76 // set the LED with the ledState of the variable:
77 digitalWrite(ledB, ledStateB);
83 1. Modificare le funzioni in modo che accettino come parametro
84 l'intervallo di lampeggio.