]> git.piffa.net Git - sketchbook_andrea/blob - oggi/BlinkWithoutDelay_4_argomento/BlinkWithoutDelay_4_argomento.ino
oggi
[sketchbook_andrea] / oggi / BlinkWithoutDelay_4_argomento / BlinkWithoutDelay_4_argomento.ino
1 /* Blink without Delay
2  Soluzione
3  
4  Introdotto un argomento per la funzione che nodifica l'intervallo di lampeggio
5  
6  */
7
8 // First LED
9 int ledA =  13;      // the number of the LED pin
10 // Variables will change:
11 int ledStateA = LOW;             // ledState used to set the LED
12 long previousMillisA = 0;        // will store last time LED was updated
13
14 // Second LED data
15 int ledB = 12; //Secondo LED
16 int ledStateB = LOW;             // ledState used to set the LED
17 long previousMillisB = 0;        // will store last time LED was updated
18
19 void setup() {
20   // set the digital pin as output:
21   pinMode(ledA, OUTPUT);      
22   pinMode(ledB, OUTPUT);  
23 }
24
25 void loop()
26 {
27   lightLedA(333);
28   lightLedB(500);
29 }
30
31 //////////////
32 // Funzioni
33
34 void lightLedA (int interval) {
35   // Illumina il ledA secondo un intervallo passato come argomento
36
37   if (millis() > previousMillisA + interval) {
38     // save the last time you blinked the LED 
39     previousMillisA = millis();   
40
41     // if the LED is off turn it on and vice-versa:
42     if (ledStateA == LOW)
43       ledStateA = HIGH;
44     else
45       ledStateA = LOW;
46     // set the LED with the ledState of the variable:
47     digitalWrite(ledA, ledStateA);
48   }
49
50 }
51
52 void lightLedB (int interval) {
53   // Illumina il ledB secondo un intervallo passato come argomento
54
55   if (millis() > previousMillisB + interval) {
56     // save the last time you blinked the LED 
57     previousMillisB = millis();   
58
59     // if the LED is off turn it on and vice-versa:
60     if (ledStateB == LOW)
61       ledStateB = HIGH;
62     else
63       ledStateB = LOW;
64     // set the LED with the ledState of the variable:
65     digitalWrite(ledB, ledStateB);
66   }
67 }
68
69 /* Approfondimenti
70 - Quali similitudini ci sono tra le due funzioni?
71 - Distinguere i dati comuni tra le due funzioni che ci servono per
72   far lampeggiare i LED
73 - Distinguere i dati che caratterizzano un LED rispetto all'altro
74 - Provare a integrare le variabili relative ai due LED dentro le 
75   rispettive funzioni.
76 - Sarebbe possibile scrivere una funzione che possa interagire con un LED qualunque?
77   ES: Come inpostare il PIN del LED? Come gestire lo stato del LED?
78 */
79
80
81
82
83
84
85