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