IRQ debounce
Posted: Sat May 29, 2021 7:02 am
Hi,
I have a rainfall sensor which I've hooked to a Raspberry Pi Pico. My testing code is the following:
I read in older topics, that in order to get the debounce working I need to disable the IRQ, read the pin state and then re-renable it. However my code hangs and IRQ is not re-enabled. Any ideas why?
I have a rainfall sensor which I've hooked to a Raspberry Pi Pico. My testing code is the following:
Code: Select all
from machine import Pin, disable_irq, enable_irq
import utime
rain_count=0
rain_sensor=Pin(7, Pin.IN, Pin.PULL_UP)
def a(p):
global rain_count
state=disable_irq()
utime.sleep_ms(50)
if p.value():
rain_count+=1
enable_irq(state)
rain_sensor.irq(handler=a,trigger=Pin.IRQ_FALLING)
while True:
print(rain_count)
utime.sleep(0.1)