Another newb here. I've been looking through examples and searching the web, but have been unable to unearth anything like what I'm attempting to do.
5 buttons (latching)
5 LED's
Let's number the buttons 1,2,3,4,5.
I would like only the oldest pressed button to blink its LED, while the others hold solid.
For instance:
Press button 2, LED 2 starts to blink.
Press button 3, LED 3 holds solid ON.
Press button 5, LED 5 holds solid ON.
Turn off button 2, LED 2 turns off, LED 3 starts to blink.
Press button 4, LED 4 holds solid ON.
Turn off button 3, LED 3 turns off, LED 5 starts to blink.
Etc.
I can't figure out how to make the program prioritize by the oldest pressed button, while still keeping them in order.
Any help writing the program or at least pointing in the right direction is much appreciated.
Thanks.
the first code construct guarantees that "doYourThing" is serviced on average every interval
The second code construct will drift in time is "doYourThing" could not be serviced every interval
You can use this construct to read buttons at a defined interval and to switch a led on/off at a certain interval
To keep track of the "age" of the switch-on you need an array which stores either 0 or the value of millis() when each switch was turned on. Change the value to 0 when the switch is turned off.
Then your code can iterate through the array to find the smallest value of mills() - that will be the switch that was first ON and its LED should flash. If there is a larger value of millis the LED should be on continuously. If a value is 0 the led should be turned off.