取消
显示结果 
搜索替代 
您的意思是: 

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 😃

下载全部
0 项奖励
1 条消息(共 7 条)
6,788 次查看

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 项奖励
2 条消息(共 7 条)
6,771 次查看

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 项奖励
3 条消息(共 7 条)
6,768 次查看

Well, here it is again, for previous versions

下载全部
0 项奖励
4 条消息(共 7 条)
6,763 次查看

2010?  😉

0 项奖励
5 条消息(共 7 条)
6,754 次查看

Here you go 😃

下载全部
0 项奖励
6 条消息(共 7 条)
6,748 次查看

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 项奖励
7 条消息(共 7 条)
6,739 次查看