LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Make boolean/LED turn off after certain time

Hi,

 

I'm working on a program where booleans have to light up to a certain protocol.

 

What I now want is for the boolean to turn off automatically after it has been turned on. So it has to be on for the half of the time to wait for the for loop to run again. 

So, if the time to wait is 1 second, the boolean has to turn on for half a second and be off for the other half a second.

 

I'm a little bit stuck here, so I hope you can help me!

If you have any questions, please ask!

 

Thank you!

0 Kudos
Message 1 of 8
(8,301 Views)

The answer is the most common one in this forum, which we have to repeat again and again 🙂 State Machine. You want to learn how to program a state machine. It is the proper solution for your problem, for example with your solution, there is no way to abort the timing parts... So a FOR loop is not really a good approach here.

 

In a State Machine design you have several states, and between these states the user or certain conditions initiate transitions.

Message 2 of 8
(8,273 Views)

I have attached a simple state machine example with a timer function. Note that, this was never intended to be a real application, but I used it for educational purposes to show different basic concepts to my students. Like States and their transitions, possible problems/issues with error handling, how to disable/enable Control buttons (to disable users creating unprogrammed states), etc...

 

This example could give you some idea how to programm different states when you have to deal with timing.

Note the Wait (msec) function in the main While loop! It is intended to avoid overusing your PC's CPU (so do not lower this value lets say below 10 msec), and also it will give you timing. The Timer subVI will check the elapsed time every 50 msec in this case, and stop the ongoing state.

 

EDIT1: It is also important to emphasize that here we use software timing. It is only as accurate as the OS you use. Since Windows is not a real time OS, your required 500 msecond wait for example will not be exactly 500 msec. Can be 505, 495, etc... That is why usually I do not go below 10 msec in such While loop (here in the example I used 50 msec). If you use 10 msec wait in this While loop, you can see that your time resolution will be maximum this accurate (+- 10 msec).

0 Kudos
Message 3 of 8
(8,251 Views)

Hello,

 

In order to split the loop time to do operations you are going to have to  run the loop time at a faster rate and then keep track of the time so that after a threshhold, you could do something, for ex.(shut off that LED). The loop time in the example below will be running 10 times faster that the loop time control. So after 500ms the case state can do an operation. Try it out, and by the way, state machines are awesome and are also an alternative but may be overkill for simple operations.

 

God Bless!

 

shut off LED.png

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

Wisdom is the principal thing; therefore get wisdom: and with all thy getting get understanding. Proverbs 4:7
Message 4 of 8
(8,243 Views)

Parallel loop or subVI:

No polling, modular, good control.

Kill notifier from main UI to quit

 

turn off boolean.png

 

0 Kudos
Message 5 of 8
(8,220 Views)

Hi Marcano,

 

I had never seen a shift register with multiple elements like that! Thanks for sharing

0 Kudos
Message 6 of 8
(8,214 Views)

No Problem, you can pull down on the shift register icon and add previous iterations of the shift register (aka history). It's a nice feature.

 

Thanks

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

Wisdom is the principal thing; therefore get wisdom: and with all thy getting get understanding. Proverbs 4:7
0 Kudos
Message 7 of 8
(8,205 Views)

If you use a feeback node instead, you would only need once instance of the ticker. 😄

 

 

(example from here)

0 Kudos
Message 8 of 8
(8,155 Views)