The EdgieD Arduino State Change Detection Library

EdgieD Library v1.0.0 
Crunchysteve, ©2024.
Proudly developed and tested in VS Code and Wokwi.com 

Quick Install
For most people, open ArduinoIDE, open the Library Manager, search EdgieD and click "Install." 

For tools like PlatformIO, download the zip and install in your libraries folder the usual way or use git in the Terminal. 

What is EdgieD?
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... 
    timing functions to repeat on a trigger input, 
    debouncing input buttons (use delay() around 5 to 20mS in your test "if()") 
    synchronising output signals to input signals. These are just a few examples! 

How It Works

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 declared instance of the library...

    eg:  myEdge.detect(state,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. 

How To Use It In Your Code
Include the EdgieD library header, 
          #include <EdgieD.h>

initialise an instance,
    Edge myEdge;

then call it,
    if(myEdge.detect(test_value, Rising [or Falling]){
        // do something 
    

If a Rising edge has been detected, the functions inside the if statement runs and the code will "do something"

"Rising" is the default state and the edge parameter can be left out for rising edges, the previous edge state is held in a private static variable inside each instance. 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.

Licence
The EdgieD Library is free software, please see "LICENCE" in the repo. for more details.

Comments

Popular posts from this blog

Removing Ollama From My Mac

Bike Porn

ALWAYS read the PDS