LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I want to create a traffic light sequence in labview

Solved!
Go to solution
Highlighted

Hi,

 

I'm very new to Labview(first post here) and am learning by trying some simple things.

 

I'm trying to create a continuous running traffic light system, RED, THEN RED AND AMBER, THEN JUST GREEN, THEN JUST AMBER, THEN JUST RED, and repeat the sequence.

 

I've got 3 LED's of the 3 colours and at the moment they run, RED, THEN RED AND AMBER, THEN RED AND AMBER AND GREEN, THEN ALL OFF, and the sequence then repeats.

 

I've used a case structure within a while loop.  Set a state for each colour and the reset(all off).  Straight forward I think.

 

Does anyone have any tips on how i might add to what I've got to create the aforementioned traffic light sequence? 

 

Many thanks for your time.

 

PJ.

0 Kudos
Message 1 of 12
(18,000 Views)
Highlighted

Since you are learning you get an image and not a snippet or vi. 

 

TrafficLight.png

 

The key is the array of clusters, each cluster has a ring and an integer.  The ring has descriptive names for each state and a value.  You must uncheck 'sequential values' and then give each state a value which corresponds to the binary equivalent of the state (exercise for the reader).  Array to Cluster must be configured to output the correct size cluster (3).

 

 

0 Kudos
Message 2 of 12
(17,982 Views)
Highlighted

Hey PJ,

 

Just a hint for when you are asking for help......  attach your vi. 

 

Most of the time it is easier for someone to see what you have done so far and then nudge you in the right direction.

0 Kudos
Message 3 of 12
(17,981 Views)
Highlighted

Thanks for the image and the help Darin.

 

I understand some parts but the other bits are new to me but I will endeavor to work them out.

 

Being a newbie I'm trying to learn some in my own time with what i think will be straight forward tasks or experiments so i learn as i play.  I have been on the Labview core 1 course which work asked me to do but i have yet to be asked to do any Labview for work and i don't want to forget what i've learned.

 

Thanks again.

 

PJ.

0 Kudos
Message 4 of 12
(17,955 Views)
Highlighted

Hey Bryan,

 

Thanks for the advice.  I guess being a newbie i'm a bit embarrassed to show my early attempts but in the future I will.

 

Cheers.

0 Kudos
Message 5 of 12
(17,953 Views)
Highlighted

Here was the VI i came up with.  Any feedback would be welcome regarding any aspect.

 

Cheers.

Message 6 of 12
(17,946 Views)
Highlighted

Pretty good for a beginner.

 

You will want to study Darin's ideas because he offers some things whaich are much more flexible and easier to modify. His method also provides for different time for each phase.

 

If you select Clean Up Diagram from the Edit menu, you get a mush more compact and readible diagram.  Keeping thewires straight does not make the program work any better, but it does make it easier to read, troubleshoot, and eventually to modify.

 

Consider making the state enum a typedef. By doing so all the copies of the constants will be updated automatically if you make any changes, such as adding a Left Turn arrow or Walk light. 

 

You may want to intialize the shift register so the VI will always start in a known state.

 

Lynn

0 Kudos
Message 7 of 12
(17,939 Views)
Highlighted

Hi Lynn,

 

Thanks for the feedback.

 

Yes i did find that i had to copy and paste the state enum every time i made a change, so i will take your advice and look into a typedef for it.

 

I wanted to start with something straight forward that i could add on to and modify and hence learn as I go along.  As you say Darin's design is the sort of thing I'm hoping to steadily move towards and I will learn about what each part does as I go.  Yes i will now add in a initialiser for the shift register i thought that from the start i needed to.

 

Kind regards.

 

PJ.

0 Kudos
Message 8 of 12
(17,917 Views)
Highlighted

Hey Darin,

 

I'm trying to re-create your VI but I'm having trouble understanding how to create the block of data containing the list and integers.  I take it its something to do with arrays of clusters but unfortunately google is not being helpful and its a beyong my level of knowledge.

Does that block on the left of your picture appear on the front panel and is represented by the 'Sequence' symbol on the block diagram?

 

Thanks for any help.

 

PJ.

0 Kudos
Message 9 of 12
(17,886 Views)
Highlighted
Solution
Accepted by topic author blast_uk

You have passed the test, so I will attach the VI this time (LV9, let me know if you need an earlier version).  You'd be surprised how many people will complain about not being provided code, glad to see you are a good sport.

 

The cluster array constant was created by right-clicking the control and choosing Create Constant.  It simply let me show in a screenshot the contents of the Sequence Array.

 

I added the delay as a little hint to always be thinking one move ahead.  Eventually you will be thinking many more moves ahead, but start out by considering the next thing you'll want to do and try to keep your code flexible enough to handle it.

 

 

Message 10 of 12
(17,872 Views)