Skip to content

Commit 867f2f8

Browse files
authored
Merge pull request #6 from dastels/Dans_suggestions
Incorporate Dan Halbert's suggestions
2 parents c7a4a8e + 70cb1ca commit 867f2f8

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

adafruit_debouncer.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@
4747

4848
import time
4949
import digitalio
50+
from micropython import const
5051

51-
_DEBOUNCED_STATE = 0x01
52-
_UNSTABLE_STATE = 0x02
53-
_CHANGED_STATE = 0x04
52+
_DEBOUNCED_STATE = const(0x01)
53+
_UNSTABLE_STATE = const(0x02)
54+
_CHANGED_STATE = const(0x04)
5455

5556
class Debouncer(object):
5657
"""Debounce an input pin or an arbitrary predicate"""
@@ -68,10 +69,7 @@ def __init__(self, io_or_predicate, interval=0.010):
6869
if self.function():
6970
self._set_state(_DEBOUNCED_STATE | _UNSTABLE_STATE)
7071
self.previous_time = 0
71-
if interval is None:
72-
self.interval = 0.010
73-
else:
74-
self.interval = interval
72+
self.interval = interval
7573

7674

7775
def _set_state(self, bits):

0 commit comments

Comments
 (0)