There's documented debounce function for the pyboard that can easily be adapted for use on the WiPy. http://www.eng.utah.edu/~cs5780/debouncing.pdf#page=19 isn't really fond of that counting algorithm but for starters I'm ok with that.
However, the 'while True: wait' section bothers me a little and I want to do that with an IRQ instead. So, I use something like this
Code: Select all
def toggle_led(pin):
# counting algorithm here
..
while active < 20:
...
led.toggle()
pin_int.irq(trigger=Pin.IRQ_RISING, handler=toggle_led)
Question 2: I don't like it that debounce is tied to the actual interrupt action (toggling the LED), how can this be fixed? It'd be nice to have a generic debounce that executes an action when done, something like 'debounce(pin, toggle_led)'.