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

Hardware:

Not all hardware / CircuitPython combinations are capable of running the debouncer correctly for an extended length of time. If this line works on your microcontroller, then the debouncer should work forever:

from time import monotonic_ns

If it gives an ImportError, then the time values available in Python become less accurate over the days, and the debouncer will take longer to react to button presses.

Software and Dependencies:

class adafruit_debouncer.Debouncer(io_or_predicate, interval=0.01)

Debounce an input pin or an arbitrary predicate

current_duration

Return the number of seconds since the most recent transition.

fell

Return whether the debounced value went from high to low at the most recent update.

interval

The debounce delay, in seconds

last_duration

Return the number of seconds the state was stable prior to the most recent transition.

rose

Return whether the debounced value went from low to high at the most recent update.

update()

Update the debouncer state. MUST be called frequently

value

Return the current debounced value.