ALERT - It's been brougfht to my attention that, in an incremental update earlier this year, EdgieD stopped working as multi object code and now only works as a "singleton." Finding this bug is taxing my limited skill. Yeah, that's how we learn I guess, meanwhile, I feel obbliged to recommend people use Bounce2, Bugtton or similar. My apologies. As an amateur and self taught coder, I can't promise a repair will be quick. Hopefully I can get my head around this monster I've created.
I'm also not too proud to ask for help. If anybody can see what I've done wrong and explain it for a "bear of little brain" I will be eternally grateful, even if, like John Cleese's grumpy centurian, you make me write it out 100 times before dawn...
Apologies, Crunchy
For most people, use the Arduino Library Manager in Arduino IDE but...
Sketch/Include Library/Add .ZIP Library
menu, For PlatformIO, update ~/[your_project/]/platformio.ini
lib_deps parammeter to include https://github.com/crunchysteve/EdgieD-1.0.0.git
I'm still learning this git stuff, I'm a hobbyist coder trying to leave my mark, and I'm both fascinated with git and utterly flabbergasted at the mind boggling complexity of git all at once. A huge thanks to @per1234 for their patient guidance through getting my library updated. I was getting quite "flappy" for a while there, they never gave up on helping me understand. (As of 20240116@1050, I have everything crossed that I've got it right at last. 24 hours or so should tell me.)
Loosely based on the button edge detection tutorial at... https://www.arduino.cc/en/Tutorial/BuiltInExamples/StateChangeDetection
...but generalised for working with variables and other coded binary state changes. It can read digital inputs to detect a button state change, the state change of a variable during runtime, the output state of a timer or the output states of other custom libraries.
The included example detects the default "leading edge" (as pressed) of a button, attached between pin 2 and ground, not changing output state again until released, then pressed again.
It can be used for...
These are just a few examples!
EdgieD compares the states of an input, a variable or output from another function with the previously measured state and whether the edge is leading or trailing, to precisely time function calls to the edge of a frequently changing state. By passing the current state, the previous state (as variables) and the preferred edge (via custom macros, LEADING and TRAILING) to a decalred instance of the library (eg "myEdge.detect(state,oldState,LEADING)" to detect a leading/rising edge), one can time other functions precise to the moment of the state change with no more than normal Arduino latencies. The code is basic C++ with now hardware specific calls, so it should work an anything from an Adafruit to a Wio-Terminal and beyond.
if(myEdge.detect(test_value,Rising){ // do something }
See the included example, EdgieD_Basic.ino for more details.
EdgieD is non-blocking and only takes as long as its lines of code to run.
The Quick Start guide is available on the wiki, as is the more detailed Documentation and feature roadmap.
The EdgieD Library is free software, please see "LICENCE". for more details.