adafruit_debouncer
Debounces an arbitrary predicate function (typically created as a lambda) of 0 arguments. Since a very common use is debouncing a digital input pin, the initializer accepts a DigitalInOut object instead of a lambda.
Author(s): Dave Astels
Implementation Notes
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases
Adafruit Ticks library: https://github.com/adafruit/Adafruit_CircuitPython_Ticks
- class adafruit_debouncer.Button(pin: ROValueIO | Callable[[], bool], short_duration_ms: int = 200, long_duration_ms: int = 500, value_when_pressed: bool = False, **kwargs)
Debouncer for buttons. Reports
pressed
andreleased
for the button state. Counts multiple short presses, allowing to detect double clicks, triple clicks, etc. Reports long presses separately. A long press can immediately follow multiple clicks, in which case the long click will be reported in the same update as the short clicks.- Parameters:
pin (DigitalInOut/function) – the DigitalIO or function to debounce.
short_duration_ms (int) – the maximum length of a short press in milliseconds.
long_duration_ms (int) – the minimum length of a long press in milliseconds.
value_when_pressed (bool) – the value of the predicate when the button is pressed. Defaults to False (for pull up buttons).
- class adafruit_debouncer.Debouncer(io_or_predicate: ROValueIO | Callable[[], bool], interval: float = 0.01)
Debounce an input pin or an arbitrary predicate
- property fell: bool
Return whether the debounced value went from high to low at the most recent update.
- property last_duration: float
Return the number of seconds the state was stable prior to the most recent transition.