microbit-foundation / micropython-microbit-v2

Temporary home for MicroPython for micro:bit v2 as we stablise it before pushing upstream
MIT License
42 stars 23 forks source link

Feature request: Work around for interrupt counter - Button class for any GPIO pin #88

Open Hybricks opened 2 years ago

Hybricks commented 2 years ago

Hi,

I understand microbit does not offer support for event handlers or for managing interrupts. Too bad, but the reasons are clear. However, the Button class contains functions which are interrupt driven (get presses(), is_pressed).

Would it be possible to do a little tweak in the Button class object to make it available on all GPIO pins?

This would allow the function .get_presses() to work as an interrupt counter, opening all sorts of great possibilities like doing RPM counters.

Please have a look at attached sample code.

What do you think? Would this work? Do I have to change this myself in the DAL (brrrr)?

Button class for any GPIO pin.txt