Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5010

MicroPython • Hardware .irq Interrupt on Button Push Difficulty

$
0
0
Hello,
I am trying to incorporate a simple push button using a hardware interrupt. The challenge I am having is a single button push can generate multiple (up to three or four) 'trigger' events. I can not seem to 'debounce' the button. I am on micropython v1.23.0 This is the code I am using:

Code:

from machine import Pinimport timebutPin=20press=0def IntSwitch(pin):    watchButton.irq(handler=None) #turn irq off to prevent bounce    global press    press=press+1    print(press)    time.sleep(.1)    watchButton.irq(trigger=Pin.IRQ_RISING, handler=IntSwitch) #turn irq back onwatchButton=Pin(butPin,Pin.IN,Pin.PULL_UP)watchButton.irq(trigger=Pin.IRQ_RISING, handler=IntSwitch)while True:    pass    
Playing with sleep time, and also does not matter if I try to turn off .irq in call back or not, nothing seems to work. What am I missing?
Thanks,
Paul McWhorter

Statistics: Posted by mcwhorpj — Sat Jul 20, 2024 4:02 pm



Viewing all articles
Browse latest Browse all 5010

Trending Articles