From: Andrea Manni <andrea@piffa.net>
Date: Mon, 21 Dec 2015 16:06:24 +0000 (+0100)
Subject: Multitasking
X-Git-Url: http://git.piffa.net/web?a=commitdiff_plain;h=ad099ab55511687f6668fbfe06a0dd6070693e80;p=sketchbook_andrea

Multitasking
---

diff --git a/multitasking/BlinkWithoutDelay_1/BlinkWithoutDelay_1.ino b/multitasking/BlinkWithoutDelay_1/BlinkWithoutDelay_1.ino
index 5096739..bdc5802 100644
--- a/multitasking/BlinkWithoutDelay_1/BlinkWithoutDelay_1.ino
+++ b/multitasking/BlinkWithoutDelay_1/BlinkWithoutDelay_1.ino
@@ -57,6 +57,8 @@ void loop()
       ledState = HIGH;
     else
       ledState = LOW;
+    // e' possibile semplificare queta operazione?
+    // Hint: lo stato del LED e' binario: ha solo due stati possibili.
 
     // set the LED with the ledState of the variable:
     digitalWrite(ledPin, ledState);
@@ -67,4 +69,4 @@ void loop()
    1. Aggioungere un LED che brilli ogni 500ms
    2. E' ora agevole cambiare gli intervalli dei due LED? 
       Modificare gli intervalli dei due led (es 500ms - 320ms)
-   */
+ */
diff --git a/multitasking/BlinkWithoutDelay_2_led/BlinkWithoutDelay_2_led.ino b/multitasking/BlinkWithoutDelay_2_led/BlinkWithoutDelay_2_led.ino
index 6bad7cd..89f5793 100644
--- a/multitasking/BlinkWithoutDelay_2_led/BlinkWithoutDelay_2_led.ino
+++ b/multitasking/BlinkWithoutDelay_2_led/BlinkWithoutDelay_2_led.ino
@@ -54,6 +54,7 @@ void loop()
   // the LED is bigger than the interval at which you want to 
   // blink the LED.
 
+// First LED
   if(millis() - previousMillisA > intervalA) {
     // save the last time you blinked the LED 
     previousMillisA = millis();   
@@ -67,6 +68,7 @@ void loop()
     digitalWrite(ledA, ledStateA);
   }
   
+// Second LED
     if(millis() - previousMillisB > intervalB) {
     // save the last time you blinked the LED 
     previousMillisB = millis();   
diff --git a/multitasking/BlinkWithoutDelay_3_funzione/BlinkWithoutDelay_3_funzione.ino b/multitasking/BlinkWithoutDelay_3_funzione/BlinkWithoutDelay_3_funzione.ino
index 63a324e..a5db67b 100644
--- a/multitasking/BlinkWithoutDelay_3_funzione/BlinkWithoutDelay_3_funzione.ino
+++ b/multitasking/BlinkWithoutDelay_3_funzione/BlinkWithoutDelay_3_funzione.ino
@@ -19,6 +19,7 @@ long previousMillisA = 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)
+void lightLedA () ;
 
 //////////////
 // Second LED
@@ -26,6 +27,7 @@ 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)
+void lightLedB () ;
 
 
 void setup() {
@@ -61,7 +63,7 @@ void lightLedA () {
 
 void lightLedB () {
   long intervalB = 500;
-   static int ledStateB ;  
+   static int ledStateB ;  // https://www.arduino.cc/en/Reference/Static
   if(millis() - previousMillisB > intervalB) {
     // save the last time you blinked the LED 
     previousMillisB = millis();   
diff --git a/multitasking/BlinkWithoutDelay_6_class/BlinkWithoutDelay_6_class.ino b/multitasking/BlinkWithoutDelay_6_class/BlinkWithoutDelay_6_class.ino
index fa55a1b..2744341 100644
--- a/multitasking/BlinkWithoutDelay_6_class/BlinkWithoutDelay_6_class.ino
+++ b/multitasking/BlinkWithoutDelay_6_class/BlinkWithoutDelay_6_class.ino
@@ -42,8 +42,8 @@ public:
 };
 
 // Instanziamo i due led dalla classe 
-Lampeggiatore ledA(1, 1000);
-Lampeggiatore ledB(2, 500);
+Lampeggiatore ledA(13, 1000);
+Lampeggiatore ledB(12, 500);
 
 void setup() {
 }
diff --git a/multitasking/blink_0_soluzione/blink_0_soluzione.ino b/multitasking/blink_0_soluzione/blink_0_soluzione.ino
index 3a3751a..e9312e0 100644
--- a/multitasking/blink_0_soluzione/blink_0_soluzione.ino
+++ b/multitasking/blink_0_soluzione/blink_0_soluzione.ino
@@ -4,12 +4,12 @@
  Aggiungere un secondo LED e farlo brillare ogni 500ms
  mentre il primo brilla ogni 1000ms
  
- a  |  b
- ========
- 1  |  1
- 1  |  0
- 0  |  1 
- 0  |  0
+ a  |  b    Changes
+ ========   =========
+ 1  |  1    x   |   x
+ 1  |  0        |   x
+ 0  |  1    x   |   x
+ 0  |  0        |   x
  
  Periodo = 500ms
  
@@ -52,6 +52,11 @@ void loop() {
   ;
 }
 
+/* Domande
+ 1. Altro scenartio: fare brillare un LED ogni 300ms mentre il secondo brilla ogni 400m
+ 2. Aggiungere un terzo LED
+ */
+