]> git.piffa.net Git - sketchbook_andrea/blob - basic/blink_sviluppo/blink_3_variables_two_led_functions_arguments_button/blink_3_variables_two_led_functions_arguments_button.ino
Blink sviluppo.
[sketchbook_andrea] / basic / blink_sviluppo / blink_3_variables_two_led_functions_arguments_button / blink_3_variables_two_led_functions_arguments_button.ino
1 /*
2   Blink v3
3  Now with 2 variables and an extra LED (remember a ~320 ohms resistor).
4  Turns on an LED on for one second, then off for one second, repeatedly.
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 red = 12;
13 int button = 2;
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   pinMode(button, INPUT);
23 }
24
25 // the loop routine runs over and over again forever:
26 void loop() {
27  if (digitalRead(button) == HIGH) { // HIGH sta per +5v
28    lightRed(breve);
29  }
30  if (digitalRead(button) == LOW) { // LOW sta per 0v                  
31    lightGreen(breve);
32  }
33 }
34
35 void lightRed(int length) { // Argomento
36   digitalWrite(red, HIGH);   // turn the LED on (HIGH is the voltage level)
37   delay(length);               // wait for a second
38   digitalWrite(red, LOW);    // turn the LED off by making the voltage LOW
39   delay(length); 
40 }
41
42 void lightGreen(int  length) {
43   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
44   delay(length);               // wait for a second
45   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
46   delay(length);               // wait for a second
47 }
48