Description
The issue is that there is a delay between the interrupt being triggered, and when this line of code executes:
NodeManager/NodeManagerLibrary.ino
Line 1549 in 4525b56
The delay is typically 2ms if SERVICE_MESSAGES is not enabled, and 200-1500ms if SERVICE_MESSAGES is enabled.
Say _mode==FALLING
, and the pin receives a very brief pulse (e.g. a very brief push of a button); by the time this line of code runs the input may have gone high again, so (_mode == FALLING && value == LOW)
will return false, and the method will interpret this as an invalid value.
My use case is a push button where I want to measure the length of time the button was pressed for. I've created a custom sensor that subclasses SensorSwitch; in the onInterrupt() method I need to be able to reliably tell whether the interrupt was triggered by a FALLING edge (button pushed) or a RISING edge (button released), even if the button was pushed so briefly that the pulse is only a few ms long.
I believe the only reliable way to detect whether a CHANGE interrupt was triggered by a RISING or FALLING edge is to read the pin as the very first instruction in the ISR (and store it somewhere for later use).
Apologies if that doesn't make sense (struggling with words today), happy to clarify if needed.
Activity