I am writing a simple code in the esp32 that has 2 buttons: one is an interrupt the other is a normal input.
when the interrupt is pressed the led lights up until the limit switch is pressed then turn back off.
Any solutions?
#include <Arduino.h>
// Pin to which the button, PIR motion detector or radar is connected #define PIN_BUTTON 4 #define PIN_LED 16 #define PIN_LIMIT 5
// Uncomment to not put the function in the RAM of the ESP32
//void buttonpressed() {
// The function is placed in the RAM of the ESP32.
void IRAM_ATTR buttonpressed() {
int val=digitalRead(PIN_LIMIT);
while (val){
Serial.print(val);
val=digitalRead(PIN_LIMIT);
digitalWrite(PIN_LED,HIGH);
delay(20);
}
}
You can use the ESP Exception Decoder to get better error messages. You problem is that you have while-loops and delays in an interrupt handler - interrupt handlers are supposed to execute as fast as possible.