const int boton1Pin = 2;
const int boton2Pin = 3;
const int ledPin = 10;
// togle
volatile bool ledEncendido = false;
volatile bool boton1Presionado = false;
void setup() {
// put your setup code here, to run once:
pinMode(boton1Pin, INPUT_PULLUP);
pinMode(boton2Pin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
attachInterrupt(digitalPinToInterrupt(boton1Pin), boton1Interrupcion, FALLING);
attachInterrupt(digitalPinToInterrupt(boton2Pin), boton2Interrupcion, FALLING);
}
void loop() {
// put your main code here, to run repeatedly:
if(ledEncendido ){
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
}
void boton1Interrupcion(){
boton1Presionado = !boton1Presionado;
if (boton1Presionado){
ledEncendido = true;
}
}
void boton2Interrupcion() {
boton1Presionado = false;
ledEncendido = false;
digitalWrite(ledPin, LOW);
}