]> git.piffa.net Git - sketchbook_andrea/blob - basic/blinks/blink_2_funzioni/blink_2_funzioni.ino
PWM
[sketchbook_andrea] / basic / blinks / blink_2_funzioni / blink_2_funzioni.ino
1
2 // ////////////
3 // Commento iniziale
4 /*
5   Blink v2
6  
7  Accensione e spegnimanto di un LED utilizzando funzioni
8  per comandare il lampeggio.
9  
10  This example code is in the public domain.
11  */
12 // //////////////
13 // Dichiarazione variabili
14
15 // Pin 13 has an LED connected on most Arduino boards.
16 // give it a name:
17 int led = 13;
18 int breve = 200;  // Variabile richiambile nel corso dell'esecuzione
19 int lunga = 1000;
20
21 // /////////////////
22 // Setup
23 void setup() {                
24   // initialize the digital pin as an output.
25   pinMode(led, OUTPUT);     
26 }
27
28 // ///////////////
29 // loop
30 void loop() {
31   rapido(); // accende e spegne rapidamente il LED
32   rapido(); // accende e spegne rapidamente il LED
33   lento();  // accende e spegne lentamente il LED
34 }
35
36 // ///////////////
37 // Funzioni create dall'utente:
38
39 void rapido() {
40   // Accende e spegne rapidamente il LED
41
42   // sequenze di istruzione: accendere e spegnere il LED
43   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
44   delay(breve);               // wait for a second
45   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
46   delay(breve);               // wait for a second
47 }
48
49 void lento() {  
50   // Accende e spegne lentamente il LED
51
52   // sequenze di istruzione: accendere e spegnere il LED
53   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
54   delay(lunga);               // wait for a second
55   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
56   delay(lunga); 
57 }
58
59