#define LED_ROJO 19 //DECLARO LOS PINES
#define BOTON 14 //DECLARO LOS PINES
#define INTERRUPTOR 4 //DECLARO LOS PINES
boolean estadoBoton; //AQUÍ SE GUARDA EL DATO DEL BOTON 1/0
boolean estadoInterruptor;//AQUÍ SE GUARDA EL DATO DEL INTERRUPTOR 1/0
void setup() {
Serial.begin(115200); //ACTIVAR COMUNICACION SERIAL
pinMode(INTERRUPTOR, INPUT);//Configura "INTERRUPTOR" como entrada
pinMode(LED_ROJO, OUTPUT); //Configura "LED_ROJO" como salida
pinMode(BOTON, INPUT);//Configura "BOTON" como entrada
}
void loop() {
estadoInterruptor = digitalRead(INTERRUPTOR); //ALMACENO EL ESTADO DEL INTERRUPTOR
if(estadoInterruptor == HIGH){//PREGUNTAMOS POR EL ESTADO DEL INTERRUPTOR
estadoBoton = digitalRead(BOTON); //ALMACENO EL ESTADO DEL BOTON
if(estadoBoton == HIGH){ //PREGUNTAMOS POR EL ESTADO DEL BOTON
EncenderLed();
}else{ //Si no
ApagarLed(); //Activar el pin digital "LED_ROJO" como valor BAJO
}
}
}
void EncenderLed(){
digitalWrite(LED_ROJO, HIGH);
Serial.println("Led Activo");
delay(1000);
}
void ApagarLed(){
digitalWrite(LED_ROJO, LOW);
}