Better software debounce

This commit is contained in:
Michal Kunc 2023-03-05 12:29:31 +01:00
parent c732ae9bf5
commit 5ad9c67aea

View File

@ -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)