An archive of as of Saturday January 26, 2019.

Best way to capture button presses


I have a loop that checks for button presses with a count set from 1 to 1000, not sure exactly how much time that is but I was wondering if someone had some good/better code at capturing a button press.

Mine is a bit slow and doesn't always catch the first press depending on where the program is in code.

I think I read there are no interrupts because of being a real time OS so wondering what is the best way.




if you are just using GPIO and have a simple need to detect whether the button is pressed, checking the value in a loop is fine. It is a bit restrictive in that you would only reliably get button presses longer than the delay in your loop.

Another approach is to use the Capture class.
It is probably going to be more reliable at detecting presses regardless of duration.


Thanks for your help, I'll look into using Capture.