X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=basic%2Fbuttons%2Fbutton_2_serial_debug%2Fbutton_2_serial_debug.ino;fp=basic%2Fbuttons%2Fbutton_2_serial_debug%2Fbutton_2_serial_debug.ino;h=f0b41d543cb88b111a22b827b1132811c2017189;hb=0807dd2a57e859d7fc246d8eb02692ea4d0da248;hp=0000000000000000000000000000000000000000;hpb=412fa124a8e9482bb252ba40f2619f6c7880e221;p=sketchbook_andrea diff --git a/basic/buttons/button_2_serial_debug/button_2_serial_debug.ino b/basic/buttons/button_2_serial_debug/button_2_serial_debug.ino new file mode 100644 index 0000000..f0b41d5 --- /dev/null +++ b/basic/buttons/button_2_serial_debug/button_2_serial_debug.ino @@ -0,0 +1,50 @@ +/* + Input serial + + + Accensione e spegnimanto di un LED utilizzando un pin come input. + + Schemi del circuito: + - http://lab.piffa.net/schemi/button_1_bb.png + - http://lab.piffa.net/schemi/button_1_schem.png + */ + +// Pin 13 has an LED connected on most Arduino boards. +// give it a name: +int led = 13; +int input = 2; + +// the setup routine runs once when you press reset: +void setup() { + // initialize the digital pin as an output. + pinMode(led, OUTPUT); // Il PIN e' attivato come output + pinMode(input, INPUT); // Il PIN e' attivato come output + + Serial.begin(9600); // Attivazione seriale +} + +// the loop routine runs over and over again forever: +void loop() { + if (digitalRead(input) == HIGH) { // Verifica se il PIN input e' +5v + digitalWrite(led, HIGH); + Serial.println("Bottone premuto: circuito chiuso"); // Debug seriale + delay(200); + } + else { // Alterativa: se non e' +5v + digitalWrite(led, LOW); + Serial.println("Bottone libero: circuito aperto"); // Debug seriale + delay(200); + } +} + +// Modifiche: +// 1. invertire il programma facendo in modo che il led si spenga +// quando il bottone e' premuto. Consoderare come ottenere lo stesso risultato +// modificando il circuito. +// 2. Modificare il programma per far brillare il led cinque volte al secondo +// quando il bottone e' premuto. + +// Domanda: cosa succede se il jumper input non e' collegato ne al +5 ne al gound? + + +