Martin
Martin

Reputation: 7

How to check if button is pressed in a comlex code?(Arduino)

I made a "complex" code, i want to check if a button is pressed, but then i have to put a checking function to every step. How can i check if the button was pressed, in ANY time? cause if i use function for checking, it will only check it in between the two commands. thanks!

Upvotes: 0

Views: 86

Answers (1)

mactro
mactro

Reputation: 518

"Complex" doesn't really tell anything. Post a code snippet, or at least measure how long your main loop takes to execute. Anyway, you can probably connect the button to an external interrupt. Then, if a user press it, the currently executed function will be interrupted, and the interrupt handler will be executed. You should keep handler functions short, so it can finish before next interrupt arrives.

Still, in many cases it is sufficient to check the button in the main loop. If it executes at least once every 20-50ms, user won't notice any delay.

Upvotes: 1

Related Questions