I have a bit of code that is waiting for a button press. The arduino doesn't do anything while it's waiting, just sits there reading the button pin waiting for it to go high. Just to make it easier to troubleshoot any issues I want to add an LED that blinks once every 5 seconds (or so) just so I know it's all working and still running. I have used millis() and some maths by my method seems a bit clumsy and involves lots of swapping and comparing numbers. Is there a nice simple way?
Add your button checking code to the blink without delay example.
Use a library, TimerOne or MsTimer2
nickjb:
I have a bit of code that is waiting for a button press. The arduino doesn't do anything while it's waiting, just sits there reading the button pin waiting for it to go high. Just to make it easier to troubleshoot any issues I want to add an LED that blinks once every 5 seconds (or so) just so I know it's all working and still running. I have used millis() and some maths by my method seems a bit clumsy and involves lots of swapping and comparing numbers. Is there a nice simple way?
Have a look at the simpletimer library - nice and easy to use and minimal overhead and wraps up all the maths for you
Craig
I have a bit of code
Really? Where? I didn't see it.
PaulS:
I have a bit of code
Really? Where? I didn't see it.
if was only 1 bit, and therefore very small ![]()
more serious, the blink with delay example is the way to go. It uses the millis() function to schedule various tasks your sketch need to do. Oneof the tasks is to monitor the key for presses.