Never done any programming with arduinos but off the top of my head I'll break down how I would do it.
I would create a number of seperate loops for each scenario. So to try and break it down in some kind of clear fashion you would have:
Loop 1
Check if button is pressed.
If button is pressed move to Loop 2
Else return to Loop 1
Loop 2
Switch on LED
Wait for 1 second
Switch off LED
Move to Loop 3
Loop 3
Check if button is held down
If button is held down return to Loop 3
Else move to Loop 1
So to start with it checks for an input from the button, if it doesn't receive it then it returns to the start of Loop 1 and continues checking. Once it receives that input it moves to Loop 2. Loop 2 flashes the LED once and then moves to Loop 3. Loop 3 checks for an input from the button, if it receives it (indicating that the button is still being held down) it returns to the start of Loop 3 and continues to check for that input. Once it no longer detects that input it moves back to Loop 1 and the cycle starts again.
Bookmarks