A lightweight schmitt trigger for debouncing and filtering.
MIT License
pio lib install "tfeldmann/SchmittTrigger"
Assumes you have a potentiometer connected to A0 and a led connected to PIN_LED
.
PIN_LED
on potentiometer readings higher than 900
.800
PIN_LED
will be pulled LOW
.800
and 900
the LED state persists.#include <SchmittTrigger.h>
// 800 is the switch off point
// 900 is the switch on point
SchmittTrigger<int> trigger(800, 900);
void setup()
{
pinMode(PIN_LED, OUTPUT);
}
void loop()
{
trigger.input(analogRead(A0));
digitalWrite(PIN_LED, trigger.output());
}