This works with two lights and two switches. If the switch is grounded (ie. pressed) then it flashes the appropriate light. One light flashes twice as fast as the other:
// pin numbers
// switches
const int LeftSwitch = 2;
const int RightSwitch = 3;
// lights
const int LeftBlink = 11;
const int RightBlink = 10;
long interval = 500;
void setup()
{
// set the digital pin as output:
pinMode(LeftBlink, OUTPUT);
pinMode(RightBlink, OUTPUT);
// enable pull-ups
digitalWrite (LeftSwitch, HIGH);
digitalWrite (RightSwitch, HIGH);
} // end of setup
void toggleFast ()
{
if (!digitalRead (LeftSwitch))
digitalWrite (LeftBlink, !digitalRead (LeftBlink));
else
digitalWrite (LeftBlink, LOW);
} // end of toggleFast
void toggleSlow ()
{
if (!digitalRead (RightSwitch))
digitalWrite (RightBlink, !digitalRead (RightBlink));
else
digitalWrite (RightBlink, LOW);
} // end of toggleSlow
void loop()
{
delay (interval);
toggleFast ();
delay (interval);
toggleFast ();
toggleSlow ();
} // end of loop
Thanks! That code actually flashes the lights UNLESS the switches are pressed/grounded (at least on my setup; my buttons are wired as per example "Push Button Control"). The lights flash, one twice as fast an the other, when the buttons aren't pressed. They turn off when their respective button is pressed.
Is toggleFast() a standard term? I've looked around for an Arduino glossary and have found some useful info, but haven't seen that phrase before. A Google search of the phrase is not helpful...
I also don't understand your use of (!)"not". I understand it when used as a comparator, but not here.
And now that the two lights can blink independent of each other, how can I set the blink rate to be the same? (In my more recently posted sketch I had two different speeds just for distinctions sake) Being blinkers for a vehicle, it makes sense to have them blink at the same speed. I also need to figure out a brake light with its own behaviors.
Thanks a ton for your help,
Nick Gammon! I will keep marching on (somewhat blindly) and see what I can do.