Skip to content

Commit 1ab75d5

Browse files
committed
allow manually pushing state, back compatible
1 parent 49bc7fe commit 1ab75d5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

adafruit_debouncer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,14 @@ def _toggle_state(self, bits):
7373
def _get_state(self, bits):
7474
return (self.state & bits) != 0
7575

76-
def update(self):
76+
def update(self, new_state=None):
7777
"""Update the debouncer state. MUST be called frequently"""
7878
now_ticks = ticks_ms()
7979
self._unset_state(_CHANGED_STATE)
80-
current_state = self.function()
80+
if new_state is None:
81+
current_state = self.function()
82+
else:
83+
current_state = bool(new_state)
8184
if current_state != self._get_state(_UNSTABLE_STATE):
8285
self._last_bounce_ticks = now_ticks
8386
self._toggle_state(_UNSTABLE_STATE)

0 commit comments

Comments
 (0)