Debouncing with IRQ

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
Posts: 6
Joined: Mon Feb 12, 2018 9:52 pm

Re: Debouncing with IRQ

Post by dubaleeiro » Sun Mar 04, 2018 3:07 pm

Now I see... thank you very much !

what would be the best way to break the while True loop throught this interrupt? Based on the Pin.value() or does the DebouncedSwitch object has some debounced Pin state?

Thanks a lot for you patience and guidance :D

Posts: 380
Joined: Wed Apr 08, 2015 5:19 am

Re: Debouncing with IRQ

Post by SpotlightKid » Sun Mar 04, 2018 6:39 pm

Several possibilities:

1. Set a global flag variable in the callback function and check for this in the conditional of a while loop:

Code: Select all

flag = False

def cb(dummy):
    global flag
    flag = True

sw = DebouncedSwitch(pin, cb, "dummy")

while not flag:

flag = False
2. Use a mutable for the callback arg and change that within the callback:

Code: Select all

flag = [False]

def cb(flag):
    flag[0] = True

sw = DebouncedSwitch(pin, cb, flag)

while not flag[0]:
3. Or the same principle using a class as the callback arg and setting/checking an attribute on it.

Posts: 1
Joined: Tue Oct 30, 2018 1:36 am

Re: Debouncing with IRQ

Post by alexholman » Tue Oct 30, 2018 1:49 am

Any suggestions for adapting this code to work from the analog input with a threshold?

On a NodeMCU I've gotten it working a simple push button, but I'd like to adapt it to trigger from a piezo sensor. Wiring it the piezo to the input pin works, but requires hammering on the piezo, and I know from experience that it can be way more sensitive wired to an analog input with a trigger threshold set. Reading the ADC with machine.ADC(0) is easy enough, but when I try to pass the resulting object to DebounceSwitch I get an error for missing .irq method. I see that the incoming sw object needs a 'callback' method or defaults to .irq. Any suggestions for what my callback for an ADC object would be and how to set it?


Post Reply