]> git.piffa.net Git - sketchbook_andrea/blob - programming/funzioni/blink_with_functions/funzioni.ino
clean up
[sketchbook_andrea] / programming / funzioni / blink_with_functions / funzioni.ino
1 // Funzioni personalizzate
2 // Un scheda e' un documento che viene concatenato allo sketch originale
3
4 void lunga() {
5   // Blink con pausa lunga
6   
7   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
8   delay(1000);               // wait for a second
9   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
10   delay(1000);     // wait for a second
11 }
12
13 void breve() {
14     // Blink con pausa breve
15     
16   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
17   delay(200);               // wait for a second
18   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
19   delay(1000);     // wait for a second
20 }
21
22 void varia(int a = 300) { // Varia has a default value, the user can override it with an argument
23   // Lampeggia per un tempo impostato dall'utente,
24   // il default e' 300ms
25   
26   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
27   delay(a);               // wait for a second
28   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
29   delay(a);     // wait for a second
30
31 }
32
33 void lampeggia(int ripetizioni) {
34   // Accende un LED per un numero stabilito di volte
35
36   // Questa funziona accetta un parametro: ripetizioni
37   int i = 0;
38   while (i < ripetizioni) {
39     rapido();   // accende e spegne rapidamente il LED
40     i = i + 1 ; // incrementa l'iteratore
41  // i++ ;       // equivalente
42   }
43 }
44
45 int area(int latoA, int latoB) { 
46   // Calcola l'area di un rettangolo
47   // e ritorna il valore calcolato: questa funzione ha un valore di ritorno
48   // dichiarato come int
49   
50   return(latoA * latoB);
51 }