]> git.piffa.net Git - sketchbook_andrea/blobdiff - multitasking/BlinkWithoutDelay_3_funzione/BlinkWithoutDelay_3_funzione.ino
Multitasking
[sketchbook_andrea] / multitasking / BlinkWithoutDelay_3_funzione / BlinkWithoutDelay_3_funzione.ino
index a77facafd1dd0069b8cd7eec38e1ea66b141d6a1..db0ed89e2c2ba043b3e395a795bc836cc52e742a 100644 (file)
@@ -49,15 +49,12 @@ void loop()
 // Funzioni:
 
 void lightLedA () {
-  if (millis() > previousMillisA + intervalA) {
+  if (millis() - previousMillisA >=  intervalA) {
     // save the last time you blinked the LED 
-    previousMillisA = millis();   
+    previousMillisA += intervalA;
 
     // 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);
   }
@@ -67,15 +64,12 @@ 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();   
+    previousMillisB += intervalB ;
 
     // 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);
   }