I keep getting Core 1 panic'ed

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);
}
}

void setup() {
Serial.begin(115200);
pinMode(PIN_BUTTON, INPUT_PULLUP);
pinMode(PIN_LIMIT, INPUT_PULLUP);
attachInterrupt(PIN_BUTTON, buttonpressed, FALLING);

// Configure LED output
pinMode(PIN_LED, OUTPUT);
}

void loop() {
digitalWrite(PIN_LED,LOW);
}

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.

please repost the code using </>

looks like the interrupt routine, buttonpressed() does not return in a short period of time. this could be affecting other processing

what about


// Pin to which the button, PIR motion detector or radar is connected
#define PIN_BUTTON 4
#define PIN_LED 16
#define PIN_LIMIT 5

void IRAM_ATTR buttonpressed() {
    digitalWrite(PIN_LED,HIGH);
}

void setup() {
    Serial.begin(115200);
    pinMode(PIN_BUTTON, INPUT_PULLUP);
    pinMode(PIN_LIMIT, INPUT_PULLUP);
    attachInterrupt(PIN_BUTTON, buttonpressed, FALLING);

    // Configure LED output
    pinMode(PIN_LED, OUTPUT);
    digitalWrite(PIN_LED,HIGH);
}

void loop() {
    if (LOW == digitalRead (PIN_BUTTON))
        digitalWrite(PIN_LED,LOW);
}