I have several problems with my C++ Code.
I am actualy trying to get a LED blink with a simple interrupt. But nothing really works.
I have the NodeMCU esp12 e.
I have a circuit using a push button and a LED. When pushing the button, I want to cause an Interrupt and the LED to blink for a certain period of time.
It usually works. But randomly nothing happens and I get a watchdog reset.
Here is the code:
const int LED_PIN = 13;
const int BUTTON_PIN = 0;
void setup() {
Serial.begin(115200);
Serial.println("");
//set pios
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT);
//set light off at the beginning
digitalWrite(LED_PIN, LOW); //blue
attachInterrupt(BUTTON_PIN, Interrupt_Sequence, FALLING);
Serial.println("Settings Done!");
}
void loop() {
//do nothing except interrupt is detected
}
void Interrupt_Sequence(){
Serial.println("Interrupt Detected: Red");
detachInterrupt(digitalPinToInterrupt(BUTTON_PIN_RED));
//Start Countdown
for(int i = 0; i <= 5; i++){
delay(950);
digitalWrite(LED_PIN, HIGH); //blink
delay(50);
digitalWrite(LED_PIN, LOW); //blink
yield(); //gives control back to scheduler, so the watchdog does not reset
}
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), Interrupt_Sequence, HIGH);
}
I don't understand why this problem occurs. My code isn't that complicated.
Does anyone know the problem?
Thanks in advance!