Issue : I have tried a number of code variants but still cant work out why im not getting the right operation, mostly it just loops around constantly flashing the Led
Looking for idea’s on how to code it correctly.
Project LED brakelight
Operation:-
When brake on, LED flashes 3 times then stays on until brake is off.
My quasi code as below
Button1 // brake switch
Led1 // brake light
Loop()
If button1 == high;
Flash Led1 3 times, then stay high
But if button1 is low at anytime then led1 low
back to start of loop
any help appreciated
the67c:
Issue : I have tried a number of code variants but still cant work out why im not getting the right operation, mostly it just loops around constantly flashing the Led
Looking for idea’s on how to code it correctly.
It's doing exactly what your quasi code is telling it to do. Everytime the loop executes, if the brake is on, it'll flash 3 times then go high until the next loop starts. Then the code asks "is the brake on" and if it is ... well you see the result. Your code needs to remember that it's done the 3 flashes routine already and that the LED just needs to stay on until the brake is released.
At this point I might point you to learn about a start machine, which is how I’d code a more complicated machine than yours is. Google it anyway and look at the Arduino reference …
http://arduino.cc/en/Reference/SwitchCase
http://playground.arduino.cc/Code/FiniteStateMachine
In your case I might use a boolean variable, flashingDone, to indicate that the 3 flashes have been done and so don’t do them again until the brake has been released. Then when the brake is released, reset that boolean to get back to flashing operation, when called for. Hint follows …
http://arduino.cc/en/Reference/Else
Ahh very helpfull thanks for the advice il give it a go