Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PROGRAMA PARA ENCENDER Y APAGAR LEDS CON EL TECLADO
- int teclado; // Variable donde se almacenará el dato introducido por teclado
- int ama=2; // Variable donde se guardará el número de pin al que hemos conectado nuestro led amarillo
- int roj=3; // Variable donde se guardará el número de pin al que hemos conectado nuestro led rojo
- int ver=4; // Variable donde se guardará el número de pin al que hemos conectado nuestro led verde
- void setup(){
- Serial.begin(9600); // Se inicia la comunicación serial con el puerto USB
- pinMode(ama, OUTPUT); // Se configura el pin como salida
- pinMode(roj, OUTPUT);// Se configura el pin como salida
- pinMode(ver, OUTPUT);// Se configura el pin como salida
- }
- void loop(){
- if(Serial.available()>0){ // Si existen datos de entrada en el monitor serial hacer lo siguiente...
- teclado=Serial.read(); // Guardamos en la variable teclado, el dato introducido por monitor serial.
- if(teclado=='1'){ // Si el dato es igual a 1
- digitalWrite(ama, HIGH); // Se enciende el led Amarillo
- Serial.println("Led AMARILLO Encendido"); }
- if(teclado=='3'){ // Si el dato es igual a 3
- digitalWrite(roj, HIGH); // Se enciende el led Rojo
- Serial.println("Led ROJO Encendido"); }
- if(teclado=='5'){ // Si el dato es igual a 5
- digitalWrite(ver, HIGH); // Se enciende el led Verde
- Serial.println("Led VERDE Encendido"); }
- if(teclado=='2'){ // Si el dato es igual a 2
- digitalWrite(ama, LOW); // Se apaga el led Amarillo
- Serial.println("Led AMARILLO Apagado"); }
- if(teclado=='4'){ // Si el dato es igual a 4
- digitalWrite(roj, LOW); // Se apaga el led Rojo
- Serial.println("Led ROJO Apagado"); }
- if(teclado=='6'){ // Si el dato es igual a 6
- digitalWrite(ver, LOW); // Se apaga el led Verde1
- Serial.println("Led VERDE Apagado"); }
- } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement