pio lib install "tfeldmann/SchmittTrigger"
Assumes you have a potentiometer connected to A0 and a led connected to PIN_LED
.
- This will turn
PIN_LED
on potentiometer readings higher than900
. - On readings lower than
800
PIN_LED
will be pulledLOW
. - On readings between
800
and900
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());
}