]> git.piffa.net Git - sketchbook_andrea/blob - basic_programming/blink_with_functions/blink_with_functions.ino
f798b46ece3b8292e8de856279ece987783ad365
[sketchbook_andrea] / basic_programming / blink_with_functions / blink_with_functions.ino
1 /*
2   Blink con funzioni.
3   
4   Le funzioni sono una sequenza di istruzione raggruppate appunto in un a funzione.
5   Le funzioni possono accettare argomenti e avere questi pre-impostati a valori di default se omessi.
6   Le funzioni possono limitarsi a svolgere istruzionioppure elaborare valori restituendo un risultato.
7   
8  */
9
10 // Pin 13 has an LED connected on most Arduino boards.
11 // give it a name:
12 int led = 13;
13 void lunga() {
14   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
15   delay(1000);               // wait for a second
16   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
17   delay(1000);     // wait for a second
18 }
19
20 void breve() {
21   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
22   delay(200);               // wait for a second
23   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
24   delay(1000);     // wait for a second
25
26 }
27
28 void varia(int a = 1000) { // Varia has a default value, the user can override it with an argument
29   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
30   delay(a);               // wait for a second
31   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
32   delay(1000);     // wait for a second
33
34 }
35
36 // the setup routine runs once when you press reset:
37 void setup() {                
38   // initialize the digital pin as an output.
39   pinMode(led, OUTPUT);     
40 }
41
42 // the loop routine runs over and over again forever:
43 void loop() {
44   lunga() ;
45   lunga() ;
46   breve();
47   breve();
48   varia(3000);
49
50
51 }
52