X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=multitasking%2FBlinkWithoutDelay_4_argomento%2FBlinkWithoutDelay_4_argomento.ino;h=11c733875a65267fcce87e188157ff3c77d86a8f;hb=HEAD;hp=8810f2733641829ae16645ee35c92aabf0c9369f;hpb=f3ffb63f53d580f0853e6b32c8ec377a7eac67f7;p=sketchbook_andrea diff --git a/multitasking/BlinkWithoutDelay_4_argomento/BlinkWithoutDelay_4_argomento.ino b/multitasking/BlinkWithoutDelay_4_argomento/BlinkWithoutDelay_4_argomento.ino index 8810f27..11c7338 100644 --- a/multitasking/BlinkWithoutDelay_4_argomento/BlinkWithoutDelay_4_argomento.ino +++ b/multitasking/BlinkWithoutDelay_4_argomento/BlinkWithoutDelay_4_argomento.ino @@ -24,7 +24,7 @@ void setup() { void loop() { - lightLedA(1000); + lightLedA(333); lightLedB(500); } @@ -34,15 +34,12 @@ void loop() void lightLedA (int interval) { // Illumina il ledA secondo un intervallo passato come argomento - if(millis() - previousMillisA > interval) { + if (millis() - previousMillisA >= interval) { // save the last time you blinked the LED - previousMillisA = millis(); + previousMillisA += interval; // if the LED is off turn it on and vice-versa: - if (ledStateA == LOW) - ledStateA = HIGH; - else - ledStateA = LOW; + ledStateA = !ledStateA; // set the LED with the ledState of the variable: digitalWrite(ledA, ledStateA); } @@ -52,15 +49,12 @@ void lightLedA (int interval) { void lightLedB (int interval) { // Illumina il ledB secondo un intervallo passato come argomento - if(millis() - previousMillisB > interval) { + if (millis() - previousMillisB >= interval) { // save the last time you blinked the LED - previousMillisB = millis(); + previousMillisB += interval; // if the LED is off turn it on and vice-versa: - if (ledStateB == LOW) - ledStateB = HIGH; - else - ledStateB = LOW; + ledStateB = !ledStateB; // set the LED with the ledState of the variable: digitalWrite(ledB, ledStateB); }