Better software debounce
This commit is contained in:
parent
c732ae9bf5
commit
5ad9c67aea
10
counter.py
10
counter.py
@ -30,13 +30,11 @@ class ButtonHandler():
|
||||
|
||||
def handler(self, pin):
|
||||
global idx
|
||||
now = time.ticks_ms()
|
||||
if time.ticks_diff(now, self.last) < 150:
|
||||
print("Debouncing")
|
||||
else:
|
||||
print(f"Changing by {self.change}")
|
||||
pin.irq(None)
|
||||
time.sleep(0.02)
|
||||
if pin.value() == 1:
|
||||
idx += self.change
|
||||
self.last = now
|
||||
pin.irq(self.handler, trigger=Pin.IRQ_RISING)
|
||||
|
||||
|
||||
button_fwd.irq(ButtonHandler(+1).handler, trigger=Pin.IRQ_RISING)
|
||||
|
Loading…
Reference in New Issue
Block a user