From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

PUT TIMER AT TRAFFIC LIGHT

Solved!
Go to solution

So this is my question:

 

Place the traffic light into a While Loop with a timer so that it actually runs on a two-minute cycle as specified. In the first 55 seconds of a cycle, the traffic light is green. From 56 to 59 seconds, the traffic light is yellow, and from 60 seconds until 120 seconds, the traffic light is red. This process should repeat indefinitely until clicking the Abort button on the front panel turns it off.

 

So basically. this traffic light I use flat sequence. 

Please show me the simplest method to SHOW TIMER ON FRONT PANEL TO THE USER.

 

Shown below is my code 

Thank you

 

AtiraSuhaimi_0-1588786698142.png

 

0 Kudos
Message 1 of 5
(4,360 Views)

You don't need any sequence structures or local variables. All you need is a state machine that spins at a reasonable rate and goes to the next state depending on elapsed time.

0 Kudos
Message 2 of 5
(4,332 Views)
Solution
Accepted by topic author AtiraSuhaimi

See if this can give you some ideas (modify as needed):

 

 

altenbach_1-1588792751016.png

 

Message 3 of 5
(4,318 Views)

Hello, could you please explain more on this part? I did not understand how does the Constant of the traffic light affected the index array function. Next, why do you put the HR Relative second VI inside and outside the loop in addition using the subtract Boolean ?

explain.PNG

0 Kudos
Message 4 of 5
(3,320 Views)

The underlying value of an enum is an integer.  So the three colors red, yellow, green are assigned the integer values of 0, 1, and 2 (I don't know what order they were assigned).  When a "red" value is wired into the index array, it is giving the value at index 0, for example.  When you add 1 to "red", it will then become "yellow". Enums automatically roll over, so red+1=green. (note that you need to use the +1 primitive not the plain add function)

 

The HR Relative second before the loop gives the time when the program started.  Inside the loop, it gives the time at each iteration.  So subtracting the two gives the time elapsed since the program started.

Message 5 of 5
(3,317 Views)