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): def handler(self, pin):
global idx global idx
now = time.ticks_ms() pin.irq(None)
if time.ticks_diff(now, self.last) < 150: time.sleep(0.02)
print("Debouncing") if pin.value() == 1:
else:
print(f"Changing by {self.change}")
idx += self.change idx += self.change
self.last = now pin.irq(self.handler, trigger=Pin.IRQ_RISING)
button_fwd.irq(ButtonHandler(+1).handler, trigger=Pin.IRQ_RISING) button_fwd.irq(ButtonHandler(+1).handler, trigger=Pin.IRQ_RISING)