I am Using Arduino IDE to program NODEMCU. I am expecting LED should remain ON for 4 sec. But it turns OFF in less than 2 sec. Please can anyone explain me why this happening? Also I noticed that if serial monitor is used, led ON timming changes with baudrate. I don't know why this is happening.
#include <ESP8266WiFi.h>
#define LED D1 // external LED is connected to pin D2
uint8_t GPIO_pin = D2;
void ICACHE_RAM_ATTR IntCallback();
void setup(){
pinMode(D1,OUTPUT);
attachInterrupt(digitalPinToInterrupt(GPIO_pin),IntCallback,CHANGE);
}
void loop(){
digitalWrite(LED,LOW); // Turn off LED to indicated Interrupt routine ended
delay(1000); // Without this delay, LED just blinks too weakly for milliseconds
}
void ICACHE_RAM_ATTR IntCallback(){
digitalWrite(LED,HIGH); // Turn LED ON to indicate Interrupt Routine started
delay(4000); // Delay in order to keep LED ON
}
delay()in an interrupt is really a bad thing to do. You should wait in the loop, not in an ISR – chrisl Nov 21 '19 at 14:39