X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=multitasking%2FBlinkWithoutDelay_3_funzione%2FBlinkWithoutDelay_3_funzione.ino;h=e27cf55d8c4e1de6ff5e67fa5022d7826c6b6198;hb=3b78d813afb2e27ed29faa261570d2eeb8d5068d;hp=a5db67b3cb71611d4bb69ac263eb2358e86070fd;hpb=ad099ab55511687f6668fbfe06a0dd6070693e80;p=sketchbook_andrea diff --git a/multitasking/BlinkWithoutDelay_3_funzione/BlinkWithoutDelay_3_funzione.ino b/multitasking/BlinkWithoutDelay_3_funzione/BlinkWithoutDelay_3_funzione.ino index a5db67b..e27cf55 100644 --- a/multitasking/BlinkWithoutDelay_3_funzione/BlinkWithoutDelay_3_funzione.ino +++ b/multitasking/BlinkWithoutDelay_3_funzione/BlinkWithoutDelay_3_funzione.ino @@ -12,7 +12,7 @@ ///////////// // First LED -int ledA = 13; // the number of the LED pin +const int ledA = 13; // the number of the LED pin // Variables will change: int ledStateA = LOW; // ledState used to set the LED long previousMillisA = 0; // will store last time LED was updated @@ -22,8 +22,9 @@ long intervalA = 1000; // interval at which to blink (milliseconds) void lightLedA () ; ////////////// -// Second LED -int ledB = 12; //Secondo LED +// Second LED +// Now with less global variables thanks to static (see function body) +const int ledB = 12; //Secondo LED // ledState used to set the LED long previousMillisB = 0; // will store last time LED was updated // interval at which to blink (milliseconds) @@ -46,7 +47,7 @@ void loop() // Funzioni: void lightLedA () { - if(millis() - previousMillisA > intervalA) { + if (millis() > previousMillisA + intervalA) { // save the last time you blinked the LED previousMillisA = millis(); @@ -64,7 +65,7 @@ void lightLedA () { void lightLedB () { long intervalB = 500; static int ledStateB ; // https://www.arduino.cc/en/Reference/Static - if(millis() - previousMillisB > intervalB) { + if (millis() > previousMillisB + intervalB) { // save the last time you blinked the LED previousMillisB = millis();