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 const 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 // Now with less global variables thanks to static (see function body)
27 const int ledB = 12; //Secondo LED
28 // ledState used to set the LED
29 long previousMillisB = 0; // will store last time LED was updated
30 // interval at which to blink (milliseconds)
35 // set the digital pin as output:
36 pinMode(ledA, OUTPUT);
37 pinMode(ledB, OUTPUT);
50 if (millis() > previousMillisA + intervalA) {
51 // save the last time you blinked the LED
52 previousMillisA = millis();
54 // if the LED is off turn it on and vice-versa:
59 // set the LED with the ledState of the variable:
60 digitalWrite(ledA, ledStateA);
67 static int ledStateB ; // https://www.arduino.cc/en/Reference/Static
68 if (millis() > previousMillisB + intervalB) {
69 // save the last time you blinked the LED
70 previousMillisB = millis();
72 // if the LED is off turn it on and vice-versa:
77 // set the LED with the ledState of the variable:
78 digitalWrite(ledB, ledStateB);
84 1. Modificare le funzioni in modo che accettino come parametro
85 l'intervallo di lampeggio.