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
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: Union[ROValueIO, Callable[, bool]], short_duration_ms: int = 200, long_duration_ms: int = 500, value_when_pressed: bool = False, **kwargs)¶
Debouncer for buttons. Reports
releasedfor 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.
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).
- property short_count: int¶
Return the number of short press if a series of short presses has ended at the last update.
- class adafruit_debouncer.Debouncer(io_or_predicate: Union[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.
- property rose: bool¶
Return whether the debounced value went from low to high at the most recent update.
- update(new_state: Optional[int] = None) None ¶
Update the debouncer state. MUST be called frequently