LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get a T/F condition where if true it changes between true and false every 5 seconds?

Hi, I have a system where I need to turn on some water pumps depending on the placement of a fish in two tanks. I pretty much have all the code down except I want two of the pump not just to run continuously whenever they are receiving a true signal, but to be turned on for x time and turned off for y time.

For example, be on for 5 seconds and off for 5 seconds continuously.

 

I tried with a flat sequence structure with 3 sequences: on, wait for 5 seconds, and off. But could make it work.

 

Can anyone help me out?

 

Thank you.

0 Kudos
Message 1 of 9
(1,896 Views)
Check out the "Elapsed Time" express VI or make your own. When the "time has elapsed" is true, change the state of the pump.
Message 2 of 9
(1,822 Views)

Thank you for answering my thread.

 

I did try the elapsed time VI before I posted this, and tried to play around with it again. However, I can only get it to be on for 5 seconds and then it switches state for off and on really fast. I can't make it 5 seconds on and then off for 5 seconds. Does the elapsed time have a function that allows you to do exactly that?

0 Kudos
Message 3 of 9
(1,811 Views)

What is trying to say is, every time to time elapses, check the state of your pump, then change it to the opposite of what it was.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 9
(1,790 Views)

Here's a very simple example running in a loop with a 2 second switching period. Usually simple applications like this evolve to become more and more complex, so you may want to start off with a state machine so that it's easier to add features later.

2020-09-07_09-27-10.gif

Message 5 of 9
(1,760 Views)

Awesome, thank you Gregory. That almost works. However, the pump needs to only switch on and off when the initial condition is true. If the initial condition is false it needs to stay off. How do I implement that?

 

0 Kudos
Message 6 of 9
(1,731 Views)

You could just wrap the pump updating code in a case structure and wire a button to it. But this is the point where I would learn about state machines and start making different states: Initialize, Start Switching, Check Timer, Update Pump, Exit. 

 

Message 7 of 9
(1,728 Views)

Wouldnt a state machine requires I made another while loop inside my while loop, which is problematic. Sorry if I ask stupid questions, still pretty new to this programming language.

 

Could you possible make a small example? I have attached the my VI if that helps

0 Kudos
Message 8 of 9
(1,723 Views)
0 Kudos
Message 9 of 9
(1,714 Views)