1 /* Blink without Delay: Refactoring
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?
11 Variabili: http://www.maffucci.it/2011/12/15/appunti-di-programmazione-su-arduino-variabili/
17 const int ledA = 13; // the number of the LED pin
18 // Variables will change:
19 int ledStateA = LOW; // ledState used to set the LED
20 long previousMillisA = 0; // will store last time LED was updated
21 // the follow variables is a long because the time, measured in miliseconds,
22 // will quickly become a bigger number than can be stored in an int.
23 long intervalA = 1000; // interval at which to blink (milliseconds)
28 // Now with less global variables thanks to static (see function body)
29 const int ledB = 12; //Secondo LED
30 // ledState used to set the LED
31 long previousMillisB = 0; // will store last time LED was updated
32 // interval at which to blink (milliseconds)
37 // set the digital pin as output:
38 pinMode(ledA, OUTPUT);
39 pinMode(ledB, OUTPUT);
52 if (millis() > previousMillisA + intervalA) {
53 // save the last time you blinked the LED
54 previousMillisA = millis();
56 // if the LED is off turn it on and vice-versa:
61 // set the LED with the ledState of the variable:
62 digitalWrite(ledA, ledStateA);
69 static int ledStateB ; // https://www.arduino.cc/en/Reference/Static
70 if (millis() > previousMillisB + intervalB) {
71 // save the last time you blinked the LED
72 previousMillisB = millis();
74 // if the LED is off turn it on and vice-versa:
79 // set the LED with the ledState of the variable:
80 digitalWrite(ledB, ledStateB);
86 1. Modificare le funzioni in modo che accettino come parametro
87 l'intervallo di lampeggio.