LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Case Structure Traffic Light

Well, the title explains quite much of my problem, I'm trying to make a traffic light (well 2 actually) with predefined times using Case Structures, but the problem is that when the first is Red the other one I want it to be Green but I don't know why when the program starts, the Red LED turns on but the Green one doesn't until a certain period of time and the times get all messed up and doesn't seem to work simultaneously.
I'll attach both tries I've had with this.

I know there are many ways to do a traffic light, I've seen many of them around here, but I'd like to know if I can make it using Case Structures or not, and if there is a way what am I doing wrong?
The problem goes something like this
"Create a program in LabVIEW for 2 traffic lights that should have this times Red: 30s On; Green: 60s On; Amber:5s On, 1s Off, then 5s On again. If Sensor 1 &/Or Sensor 2 detect (I've put these as booleans to simulate the sensors) the times will change like this: R: 45s; G:45s; A: 5-1-5s" As you can see in the attached programs Sensor 1 controls the time for the Traffic Light #2 and viceversa.

Thanks for viewing and thanks in advance to however answers 😃

Download All
0 Kudos
Message 1 of 7
(6,521 Views)

I have not looked at your VI (do not have 2012 installed), but yes, you should be able to use a Case Structure.  Usually a state machine would do the trick.

 

How have you defined your states?

0 Kudos
Message 2 of 7
(6,504 Views)

again i dont have lv2012, if you could attach either a png screenshot of your vi or save it as a previous version for us to look at that would be great, but by the sounds of it state machines are the way forward

 

 

Please remember to accept any solutions and give kudos, Thanks


LV 8.6.1, LV2010,LV2011SP1, FPGA, Win7
0 Kudos
Message 3 of 7
(6,501 Views)

Well, here it is again, for previous versions

Download All
0 Kudos
Message 4 of 7
(6,496 Views)

2010?  😉

0 Kudos
Message 5 of 7
(6,487 Views)

Here you go 😃

Download All
0 Kudos
Message 6 of 7
(6,481 Views)

My comments are based on a very quick look at your VI.

 

I would recommend that you change the inside of you While Loop to a state machine, which has a single Case Structure.  Otherwise, you will be dealing with race conditions (which is what you are probably facing), and thus resulting in unpredictable (?) (less predictable) results.

 

Having a single case structure will be cleaner and ensure proper outcome for a given change in state.

 

I would also have a single Delay function outside (to the right) of the Case Structure and simply wire the delay value into it from the Case, unless you need to adapt the delay to circumstances, such as the sensors becoming true.  In other words, if your delay time is rather static (ie duration of red is constant, same for yellow and for green).  If dynamic.. then you may actually need to trigger events, which would mean that having an event handler might be a better approach.  It is not that much more complicated, but would handle the sensors much better. 

 

If I had the time, I would do a quick example.  😞

0 Kudos
Message 7 of 7
(6,472 Views)