]> git.piffa.net Git - sketchbook_andrea/blob - basic/blinks/blink_4_1_ciclo_for/blink_4_ciclo_for.ino
2322b56dc581b401799cb0006ad355b6b0935899
[sketchbook_andrea] / basic / blinks / blink_4_1_ciclo_for / blink_4_ciclo_for.ino
1 /*
2   Blink v4
3  Accensione e spegnimanto di un LED utilizzando un ciclo
4  iterativo for per comandare il lampeggio.
5  
6  */
7
8 // Pin 13 has an LED connected on most Arduino boards.
9 // give it a name:
10 int led = 13;
11 int breve = 200;  // Variabile richiambile nel corso dell'esecuzione
12 int lunga = 1000;
13
14 // Setup: eseguita una volta sola all'accensione della scheda
15 void setup() {                
16   // initialize the digital pin as an output.
17   pinMode(led, OUTPUT);     
18 }
19
20 // loop: Le istruzioni vengono eseguite all'infinito
21 void loop() {
22   for (int i = 0, i <10, i++) { 
23 // (Definizione iteratore, condizione di verifica, gestione dell'iteratore)
24 // Operatore ternario (3 elementi)
25       rapido(); // accende e spegne rapidamente il LED
26   }
27   
28   lento();  // accende e spegne lentamente il LED
29   // Domanda: dobbiamo preoccuparci dell'iteratore?
30 }
31
32 // Funzioni create dall'utente:
33
34 void rapido() {
35   // Accende e spegne rapidamente il LED
36
37   // sequenze di istruzione: accendere e spegnere il LED
38   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
39   delay(breve);               // wait for a second
40   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
41   delay(breve);               // wait for a second
42 }
43
44 void lento() {  
45   // Accende e spegne lentamente il LED
46
47   // sequenze di istruzione: accendere e spegnere il LED
48   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
49   delay(lunga);               // wait for a second
50   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
51   delay(lunga); 
52 }
53
54