I have an Apollo Board v1.3, which operates similarly as the arduino uno. I am trying to create a loop that makes 3 adjacent LEDs blink individually at a rate of once per second continuosly (all 3 blink individually in a 1 second time span) if no buttons are being pushed. Then if a certain button is pushed, make all 3 LEDs light up together for one second, then off for one second, then back on for one second, and so on...
For anyone asking, this is a school assignment, and the instructions are:
"While no one is pushing the button to dispense water, we want to blink all of the LEDs in sequence once per second, from top to bottom. But, while someone is pushing the button we will blink all of them (effectively) at the same time on and then off, repeating, once per second."
So far, I can only get the board to blink the 3 LEDs individually once per second.
I have attached what I have so far. If anyone can help, it would be much appreciated.
For a start, you're only reading the button once, and that's not even in setup() or loop(). (I didn't know one could do a digitalRead() outside of a function, but it does actually compile.)
So anyhoo there's a clue: the button needs to be read somewhere the while()s will see it changing.
(Second hint, maybe longer term, is that a blink without delay approach would make the sketch more responsive to the button changes, since nothing happens (ie no button read) during a delay().)
maybe, wherever you have delay(333) replace with a call to a subroutine which loops 333 times reading the button push each cycle? Some kind of debounce might help - i.e. increment a variable which triggers the state change when the switch is showing a change ten times in a row?