]> git.piffa.net Git - sketchbook_andrea/blob - basic/blinks/blink_6_funzioni_argomenti/blink_6_funzioni_argomenti.ino
blinks while
[sketchbook_andrea] / basic / blinks / blink_6_funzioni_argomenti / blink_6_funzioni_argomenti.ino
1 /*
2   Blink v6
3   
4  Due LEDs con funzioni che accettano argomenti:
5  gli argomenti permettono di modificar il comportamento
6  delle funzioni.
7  
8  */
9
10 // Pin 13 has an LED connected on most Arduino boards.
11 // give it a name:
12 int led = 13;
13 int red = 12;
14 int breve = 200;
15 int lunga = 1000;
16
17 // the setup routine runs once when you press reset:
18 void setup() {                
19   // initialize the digital pin as an output.
20   pinMode(led, OUTPUT);     
21   pinMode(red, OUTPUT);
22 }
23
24 // the loop routine runs over and over again forever:
25 void loop() {
26 lightRed(lunga);
27 lightRed(breve);
28
29 lightGreen(breve);
30 lightGreen(lunga);
31 }
32
33 void lightRed(int length) { // Argomento
34   digitalWrite(red, HIGH);   // turn the LED on (HIGH is the voltage level)
35   delay(length);               // wait for a second
36   digitalWrite(red, LOW);    // turn the LED off by making the voltage LOW
37   delay(length); 
38 }
39
40 void lightGreen(int  length) {
41   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
42   delay(length);               // wait for a second
43   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
44   delay(length);               // wait for a second
45 }
46   
47   // Test: creare una funzione generica che permetta di accendere
48   // qualunque LED per un periodo di tempo impostabile
49   
50   // Suggerimento: quanti parametri deve accettare?