Hello,
I have a sketch that flashed two LEDs back and forth as a police type pattern.. I attempted to add a third LED that flashes at the same time as the first LED, But I have something wrong..
Can someone tell me where I messed up? (besides trying to do this LOL)
In the future, please post your code inline using code tags - it makes it easier for people to view it and help you.
whichLED = !whichLED;
If whichLED is 0, that will set it to 1.
If whichLED is 1, that will set it to 0.
whichLED will never be set to 2, so it will never equal the BAR you defined.
How about:
whichLED=(whichLED==2?0:whichLED+1);
or a little if/else statement if you don't like the above.
I also don't like the way you're casting the times to long. I've never seen that done before, and I get a bad vibe from it, though doing it out in my head with reasonable values, I don't immediately find a case that'll break it.
When I run it, the LED on pin 5 (BAR) lights and strobes, then LED red lights and strobes, Then LED blue lights and strobes. The red and blue continue to strobe (flash 4 times, then switch).. The BAR LED never lights again until power is cycled..
I wish to have LED red and BAR flash together, then LED blue and then switch back and forth..
My issue is, I have three LEDs attached to each output. One output works as planned, the second output does not flash. If I unhook the third LED on the second output, it flashes as designed (my third LED loads the output pin down).. so I want to put my third LED on its own pin and flash it with the red LED output
DrAzzy:
I also don't like the way you're casting the times to long. I've never seen that done before, and I get a bad vibe from it, though doing it out in my head with reasonable values, I don't immediately find a case that'll break it.
dcr_inc:
When I run it, the LED on pin 5 (BAR) lights and strobes, then LED red lights and strobes, Then LED blue lights and strobes. The red and blue continue to strobe (flash 4 times, then switch).. The BAR LED never lights again until power is cycled..
I wish to have LED red and BAR flash together, then LED blue and then switch back and forth..
My issue is, I have three LEDs attached to each output. One output works as planned, the second output does not flash. If I unhook the third LED on the second output, it flashes as designed (my third LED loads the output pin down).. so I want to put my third LED on its own pin and flash it with the red LED output
Then my diagnosis is still correct, though the fix is different.
Well, yes, that's exactly what your code does. Read my response again, and look at your code.
You test whether WhichLED == BAR, and only change the LED_BAR state in that case. But WhichLED will never be set to BAR (2), except on the first run through.
If you want LED_BAR and LED_Red to flash at the same time, you want to change the BAR_state at the same time as the Red_State.