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: 307
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.

Post Reply