# This one is killing me! - BlinkwithoutDelay relate

I am trying to develop a program that I assumed was simple, but it's kept me up all week...

I have the following:
4 LEDs controlled by three Pots.
I have that part down pat, I can control them all independently and whatnot, with the BlinkwithoutDelay example.

However, I have a catch: Two of my LEDs need to run in a very specific timed sequence. The sequence (quadrature); 1 - ON, 2 - ON, 1 - OFF, 2- OFF, with an evenly spaced delay (determined by the pot).

So for example:
1 - ON, wait 250ms
2 - ON, wait 250ms
1 - OFF, wait 250ms
2 - OFF, wait 250ms

In the meantime, I also want the other two LEDs to pulse, without being interrupting by the first sequence.

I would post code, but I haven't made any headway from having four independently controlled LEDs.

I would really appreciate any insight anyone can provide, or some tips for getting this going.

Thanks!

Blink without Delay is the right sample to look at. Now take a pen, a piece of paper and try to solve the same thing with your watch. Use 45 seconds instead of 250ms so that you have enough time to think. Once you solved that, the solution for the program will be easy.

A hint: You will need 4 variables:

``````int blink1state; // ranging from 0 to 3 (off-off, on-off, on-on, off-on)
int blink2state; // ranging from 0 to 1 (off, on)
unsigned long blink1startphase; // When was the last switch for blink 1
unsigned long blink2startphase; // When was the last switch for blink 2
``````

That should put you on the right track.

Korman

I'm not sure if I understand, but it sounds like a lab I gave to my students, a traffic light controller (2 sets of Green-Yellow-Red lights)

It's a Windows application and uses a Timer as the key component (available in Arduino)

Light 2 works according to Light1. For example, if Light 1 is green or yellow, Light 2 is red and so on.

The way to solve the problem (if one does not want and orgy of IFs) is to think in terms of sequences.

``````SEQn   L1G  L1Y  L1R     L2G  L2Y L2R
0     ON   off  off     off  off ON
1     off  ON   off     off  off ON
2     off  off  ON      ON   off off
4     off  off  ON      off  ON  off
5     goto SEQ 0
``````

If that sounds good, I can elaborate.

I got it! Basically I used a start time ( blinkpahse1start), then every stage I took the current time. If 1/4 of my interval time had passed I would change to the next blink state. Took a bit to ace the timing, but I finally got it going.
Thanks for the encouragement