]> git.piffa.net Git - sketchbook_andrea/blob - basic/buttons/button_2_serial_debug/button_2_serial_debug.ino
RF e keypad
[sketchbook_andrea] / basic / buttons / button_2_serial_debug / button_2_serial_debug.ino
1 /*
2   Input serial debug
3  
4  
5  Accensione e spegnimanto di un LED utilizzando un pin come input.
6  
7  Schemi del circuito per bottone in pull down:
8  - http://lab.piffa.net/schemi/button_1_bb.png
9  - http://lab.piffa.net/schemi/button_1_schem.png
10  */
11
12 int led = 12;
13 int input = 2;
14
15 // the setup routine runs once when you press reset:
16 void setup() {                
17   pinMode(led, OUTPUT);       // Il PIN e' attivato come output
18   pinMode(input, INPUT);        // Il PIN e' attivato come output
19
20   Serial.begin(9600);         // Attivazione seriale
21 }
22
23 // the loop routine runs over and over again forever:
24 void loop() {
25   if (digitalRead(input) == HIGH) { // Verifica se il PIN input e' +5v
26     digitalWrite(led, HIGH);
27     Serial.println("Bottone premuto: circuito chiuso");  // Debug seriale
28     delay(200);
29   } 
30   else { // Alterativa: se non e' +5v
31     digitalWrite(led, LOW);
32     Serial.println("Bottone libero: circuito aperto");  // Debug seriale
33     delay(200);
34   }
35 }
36
37 // Modifiche: 
38 // 1. invertire il programma facendo in modo che il led si spenga
39 // quando il bottone e' premuto. Consoderare come ottenere lo stesso risultato
40 // modificando il circuito.
41 // 2. Modificare il programma per far brillare il led cinque volte al secondo
42 // quando il bottone e' premuto.
43
44 // Domanda: cosa succede se il jumper input non e' collegato ne al +5 ne al gound?
45
46
47