Advertisement
Dofiduino

ENCENDER Y APAGAR LEDS CON EL TECLADO

Jul 23rd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. //PROGRAMA PARA ENCENDER Y APAGAR LEDS CON EL TECLADO
  2.  
  3.  
  4. int teclado; // Variable donde se almacenará el dato introducido por teclado
  5. int ama=2; // Variable donde se guardará el número de pin al que hemos conectado nuestro led amarillo
  6. int roj=3; // Variable donde se guardará el número de pin al que hemos conectado nuestro led rojo
  7. int ver=4; // Variable donde se guardará el número de pin al que hemos conectado nuestro led verde
  8.  
  9. void setup(){
  10. Serial.begin(9600); // Se inicia la comunicación serial con el puerto USB
  11. pinMode(ama, OUTPUT); // Se configura el pin como salida
  12. pinMode(roj, OUTPUT);// Se configura el pin como salida
  13. pinMode(ver, OUTPUT);// Se configura el pin como salida
  14. }
  15.  
  16. void loop(){
  17. if(Serial.available()>0){ // Si existen datos de entrada en el monitor serial hacer lo siguiente...
  18. teclado=Serial.read(); // Guardamos en la variable teclado, el dato introducido por monitor serial.
  19.  
  20. if(teclado=='1'){ // Si el dato es igual a 1
  21. digitalWrite(ama, HIGH); // Se enciende el led Amarillo
  22. Serial.println("Led AMARILLO Encendido"); }
  23.  
  24. if(teclado=='3'){ // Si el dato es igual a 3
  25. digitalWrite(roj, HIGH); // Se enciende el led Rojo
  26. Serial.println("Led ROJO Encendido"); }
  27.  
  28. if(teclado=='5'){ // Si el dato es igual a 5
  29. digitalWrite(ver, HIGH); // Se enciende el led Verde
  30. Serial.println("Led VERDE Encendido"); }
  31.  
  32. if(teclado=='2'){ // Si el dato es igual a 2
  33. digitalWrite(ama, LOW); // Se apaga el led Amarillo
  34. Serial.println("Led AMARILLO Apagado"); }
  35.  
  36. if(teclado=='4'){ // Si el dato es igual a 4
  37. digitalWrite(roj, LOW); // Se apaga el led Rojo
  38. Serial.println("Led ROJO Apagado"); }
  39.  
  40. if(teclado=='6'){ // Si el dato es igual a 6
  41. digitalWrite(ver, LOW); // Se apaga el led Verde1
  42.  
  43. Serial.println("Led VERDE Apagado"); }
  44.  
  45.  
  46.  
  47. } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement