X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=multitasking%2FBlinkWithoutDelay_2_led%2FBlinkWithoutDelay_2_led.ino;h=2100ead96aaba26397c4f252881e6c134b79eac6;hb=8e9925f6950eb521d8f5a2609fc61ab3b7dcf81a;hp=293e2172a7319c2d573631f57644ee38747341ea;hpb=929cf678b6e52050584cb43055194830edc5523f;p=sketchbook_andrea diff --git a/multitasking/BlinkWithoutDelay_2_led/BlinkWithoutDelay_2_led.ino b/multitasking/BlinkWithoutDelay_2_led/BlinkWithoutDelay_2_led.ino index 293e217..2100ead 100644 --- a/multitasking/BlinkWithoutDelay_2_led/BlinkWithoutDelay_2_led.ino +++ b/multitasking/BlinkWithoutDelay_2_led/BlinkWithoutDelay_2_led.ino @@ -24,20 +24,20 @@ // constants won't change. Used here to // set pin numbers: -const int ledA = 13; // the number of the LED pin -int ledB = 12; //Secondo LED +const int ledA = 13; // Primo LED +const int ledB = 12; // Secondo LED -// Variables will change: +// Variabbili di stato int ledStateA = LOW; // ledState used to set the LED int ledStateB = LOW; // ledState used to set the LED - + long previousMillisA = 0; // will store last time LED was updated long previousMillisB = 0; // will store last time LED was updated // the follow variables is a long because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. long intervalA = 1000; // interval at which to blink (milliseconds) -long intervalB = 500; // interval at which to blink (milliseconds) +long intervalB = 500; // interval at which to blink (milliseconds) void setup() { // set the digital pin as output: @@ -47,14 +47,8 @@ void setup() { void loop() { - // here is where you'd put code that needs to be running all the time. - - // check to see if it's time to blink the LED; that is, if the - // difference between the current time and last time you blinked - // the LED is bigger than the interval at which you want to - // blink the LED. - - if(millis() - previousMillisA > intervalA) { +// Primo LED + if (millis() > previousMillisA + intervalA) { // save the last time you blinked the LED previousMillisA = millis(); @@ -67,7 +61,8 @@ void loop() digitalWrite(ledA, ledStateA); } - if(millis() - previousMillisB > intervalB) { +// Secondo LED + if (millis() > previousMillisB + intervalB) { // save the last time you blinked the LED previousMillisB = millis(); @@ -83,8 +78,10 @@ void loop() /* Domande 1. Provare a isolare il codice per accendere ogni singolo led in una funzione: - Quali variabili determinano il comportamento del LED? - Sono globali o locali? + - Quali variabili determinano il comportamento del LED? + - Come cambiano durante il corso dello script? + - Sono globali o locali? + - Quali parti vanno eseguite una sola volta e quali a ogni esecuzione? */