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):
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user