]> git.piffa.net Git - sketchbook_andrea/blobdiff - basic/buttons/button_1/button_1.ino
for
[sketchbook_andrea] / basic / buttons / button_1 / button_1.ino
index 5d840ecec927f23789759c5b3e73d7593b246596..f4090282e7000e95e3a412fc0f14333e2ccfd272 100644 (file)
@@ -1,15 +1,20 @@
 /*
-  Input
+  Input Condizionale
  
  Accensione e spegnimanto di un LED utilizzando un pin come input.
+
+ Utilizzare un jumper per collegare il PIN Input
+ alternativamente a +5 o GND .
+
+Schema:
+- http://lab.piffa.net/schemi/led_condizionale.png
 
  */
 
 // Pin 13 has an LED connected on most Arduino boards.
 // give it a name:
-int led = 13;
-int input = 8;
+int led     = 12;
+int input   = 2;
 
 // the setup routine runs once when you press reset:
 void setup() {                
@@ -20,15 +25,21 @@ void setup() {
 
 // the loop routine runs over and over again forever:
 void loop() {
-  if (digitalRead(input) == HIGH) { // Verifica se il PIN input e' +5v
+  if (digitalRead(input) == HIGH) { // Verifica se il PIN input e' +5V
     digitalWrite(led, HIGH);
   } 
-  else { // Alterativa: se non e' +5v
+  if (digitalRead(input) == LOW) { // Verifica se il PIN input e' 0V
     digitalWrite(led, LOW);
   }
 }
 
-
-// Funzioni create dall'utente:
-
-
+/* Domande:
+ 1. Invertire il programma facendo in modo che il led si spenga
+    quando il bottone e' premuto. Considerare 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.
+ 3. Si potrebbe usare un ciclo iterativo while invece che 
+    un ciclo condizonale if? Che differenza c'e' tra il ciclo while, if e  for?
+ 4. Domanda: cosa succede se il jumper input non e' collegato ne al +5 ne al ground?
+ */