]> git.piffa.net Git - sketchbook_andrea/blob - basic/blinks/blink_3_ciclo_while/blink_3_ciclo_while.ino
ff8dea5eda33db47e4a173e3f4bf0cf60439de9f
[sketchbook_andrea] / basic / blinks / blink_3_ciclo_while / blink_3_ciclo_while.ino
1 /*
2   Blink v3
3  Accensione e spegnimanto di un LED utilizzando un ciclo
4  iterativo while per comandare il lampeggio.
5  
6  This example code is in the public domain.
7  */
8
9 // Pin 13 has an LED connected on most Arduino boards.
10 // give it a name:
11 int led = 13;
12 int breve = 200;  // Variabile richiambile nel corso dell'esecuzione
13 int lunga = 1000;
14 int iterator = 0; // Defniamo un variabile per controllare un ciclo iterativo
15
16 // the setup routine runs once when you press reset:
17 void setup() {                
18   // initialize the digital pin as an output.
19   pinMode(led, OUTPUT);     
20 }
21
22 // the loop routine runs over and over again forever:
23 void loop() {
24   while (iterator <10) {
25     rapido(); // accende e spegne rapidamente il LED
26     iterator = iterator +1 ; // incrementa l'iteratore
27     // iterator++ ; // equivalente
28   }
29   lento();  // accende e spegne lentamente il LED
30   // Domanda: a quanto equivale iterator ora?
31 }
32
33 // Funzioni create dall'utente:
34
35 void rapido() {
36   // Accende e spegne rapidamente il LED
37
38   // sequenze di istruzione: accendere e spegnere il LED
39   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
40   delay(breve);               // wait for a second
41   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
42   delay(breve);               // wait for a second
43 }
44
45 void lento() {  
46   // Accende e spegne lentamente il LED
47
48   // sequenze di istruzione: accendere e spegnere il LED
49   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
50   delay(lunga);               // wait for a second
51   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
52   delay(lunga); 
53 }
54
55
56