]> git.piffa.net Git - sketchbook_andrea/blob - basic/buttons/button_1/button_1.ino
Buttons and serial
[sketchbook_andrea] / basic / buttons / button_1 / button_1.ino
1 /*
2   Input
3  
4  Accensione e spegnimanto di un LED utilizzando un pin come input.
5  
6
7  */
8
9 // Pin 13 has an LED connected on most Arduino boards.
10 // give it a name:
11 int led = 13;
12 int input = 2;
13
14 // the setup routine runs once when you press reset:
15 void setup() {                
16   // initialize the digital pin as an output.
17   pinMode(led, OUTPUT);       // Il PIN e' attivato come output
18   pinMode(input, INPUT);        // Il PIN e' attivato come output
19 }
20
21 // the loop routine runs over and over again forever:
22 void loop() {
23   if (digitalRead(input) == HIGH) { // Verifica se il PIN input e' +5v
24     digitalWrite(led, HIGH);
25   } 
26   else { // Alterativa: se non e' +5v
27     digitalWrite(led, LOW);
28   }
29 }
30
31 // Modifiche: 
32 // 1. invertire il programma facendo in modo che il led si spenga
33 // quando il bottone e' premuto. Consoderare come ottenere lo stesso risultato
34 // modificando il circuito.
35 // 2. Modificare il programma per far brillare il led cinque volte al secondo
36 // quando il bottone e' premuto.
37
38 // Domanda: cosa succede se il jumper input non e' collegato ne al +5 ne al gound?
39
40