You don’t need a full-fledge Debouncing library as it might be not written to use in ISR.
You can just use some simple debouncing way using millis()
inside ISR. For example
#define DEBOUNCE_TIME 200 // the debounce time in msec; increase if the output flickers
volatile unsigned long lastDebounceTime = 0;
volatile bool currentState = LOW;
void ICACHE_RAM_ATTR Falling()
{
unsigned long currentTime = millis();
if (currentTime > lastDebounceTime + DEBOUNCE_TIME)
{
lastDebounceTime = currentTime;
//Reverse the state
currentState = !currentState;
// Do something, such as turn ON/OFF lightPin
digitalWrite(lightPin, currentState);
}
}
void setup()
{
....
pinMode(buttonPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(buttonPin), Falling, FALLING);
....
}
The ISR will work no matter you’re blocked by something, such as blocking Blynk.begin()
. But as @PeteKnight suggests, you’d better use Blynk.config()
and Blynk.connect()
to avoid being blocked if you have something important to do in your loop()
.
The timeout period of Blynk.connect()
can be specified either in the call, such as Blynk.connect(TIMEOUT_IN_MS)
or by using the following #define
. Just place it before first #include
of any Blynk library (better the first line of your main code).
#define BLYNK_TIMEOUT_MS WANTED_TIMEOUT_DIV_3_MS
If Blynk.connect()
is called without argument, the timeout will default to 3 times of BLYNK_TIMEOUT_MS (currently 3s or 6s, depending on which device you’re using) as specified in Blynk/BlynkProtocol.h
and Blynk/BlynkConfig.h
bool connect(uint32_t timeout = BLYNK_TIMEOUT_MS*3);
You can also try this