struct Sensor {
const uint8_t PIN;
volatile bool pressed;
uint8_t state;
};
Sensor B4 = {12, false, LOW};
uint8_t pinB4;
void IRAM_ATTR ISR10L () {
B4.pressed = true;
}
void setup() {
pinMode(B4.PIN,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(B4.PIN), ISR10L, CHANGE);
Serial.begin(115200);
Serial.println("Hello, CAMBIO!");
}
void loop() {
if (B4.pressed) {
B4.state = digitalRead(B4.PIN);
Serial.print("sensor: ");
if(B4.state == LOW) {
Serial.println("ON");
}
else {
Serial.println("OFF");
}
B4.pressed = false;
}
delay(500); // this speeds up the simulation
}