]> git.piffa.net Git - sketchbook_andrea/blob - multitasking/BlinkWithoutDelay_2_2_led_funzione_argomento/BlinkWithoutDelay_2_2_led_funzione_argomento.ino
7685471f3f8a233db13a785e76a77d4ec1e88ea8
[sketchbook_andrea] / multitasking / BlinkWithoutDelay_2_2_led_funzione_argomento / BlinkWithoutDelay_2_2_led_funzione_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 // constants won't change. Used here to 
9 // set pin numbers:
10
11 // First LED
12 const int ledA =  13;      // the number of the LED pin
13
14 // Variables will change:
15 int ledStateA = LOW;             // ledState used to set the LED
16
17 long previousMillisA = 0;        // will store last time LED was updated
18
19 // the follow variables is a long because the time, measured in miliseconds,
20 // will quickly become a bigger number than can be stored in an int.
21
22
23 // Second LED data
24 int ledB = 12; //Secondo LED
25 int ledStateB = LOW;             // ledState used to set the LED
26 long previousMillisB = 0;        // will store last time LED was updated
27
28
29
30 void setup() {
31   // set the digital pin as output:
32   pinMode(ledA, OUTPUT);      
33   pinMode(ledB, OUTPUT);  
34 }
35
36 void loop()
37 {
38   lightLedA(40);
39   lightLedB(500);
40 }
41
42
43 // Funzioni
44
45 void lightLedA (int interval) {
46   // Illumina il ledA secondo un intervallo passato come argomento
47
48   if(millis() - previousMillisA > interval) {
49     // save the last time you blinked the LED 
50     previousMillisA = millis();   
51
52     // if the LED is off turn it on and vice-versa:
53     if (ledStateA == LOW)
54       ledStateA = HIGH;
55     else
56       ledStateA = LOW;
57     // set the LED with the ledState of the variable:
58     digitalWrite(ledA, ledStateA);
59   }
60
61 }
62
63 void lightLedB (int interval) {
64   // Illumina il ledB secondo un intervallo passato come argomento
65
66   if(millis() - previousMillisB > interval) {
67     // save the last time you blinked the LED 
68     previousMillisB = millis();   
69
70     // if the LED is off turn it on and vice-versa:
71     if (ledStateB == LOW)
72       ledStateB = HIGH;
73     else
74       ledStateB = LOW;
75     // set the LED with the ledState of the variable:
76     digitalWrite(ledB, ledStateB);
77   }
78 }
79
80 /* TODO
81 - Differenze tra fuznioni e programmazione a oggetti: integrazione tra
82 operativita' e dati
83 - Rapporto tra global scope e uso di pointers
84 - uso di forme di dati strutturate (array, struct) per scambiare dati tra funzioni e programma
85 */
86
87
88
89
90
91
92