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

Code: Select all
flag = False
def cb(dummy):
global flag
flag = True
sw = DebouncedSwitch(pin, cb, "dummy")
while not flag:
do_something()
flag = False
Code: Select all
flag = [False]
def cb(flag):
flag[0] = True
sw = DebouncedSwitch(pin, cb, flag)
while not flag[0]:
do_something()
Hello MicroPython loverdhylands wrote: ↑Fri May 20, 2016 10:12 pmTo debounce with an IRQ, the normal flow would go something like this:
1 - Setup pin to generate IRQ on an approriate edge
2 - In IRQ handler, disable the IRQ and start a debounce timer
3 - When the timer expires, examine the state of the pin, re-enable the edge IRQ and then do whatever callbacks are required.
You want to disable the IRQ because one switch transition will often generate multiple edges.
The disadvantge of the IRQ method is that the callback is executed in IRQ context.
I often have a main loop that runs on regular intervals (i.e. every 10 msec) so I tend to use the count method. The counting method could introduce some latency (up to 10 msec if you're running in realtime, more if you're not), but I've never really needed the "instant" reaction that requires an interrupt to be used. I'm happy to implement it when needed, but it adds considerable complexity, which means more potential failure points in your code, etc.
p0.irq(handler=None)
Thank for reply