09-04-2020 06:07 PM
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.
09-05-2020 11:22 AM
09-05-2020 02:42 PM
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?
09-05-2020 08:17 PM
What Gregory 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.
09-07-2020
11:31 AM
- last edited on
05-13-2025
01:09 PM
by
Content Cleaner
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.
09-09-2020 07:42 PM
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?
09-09-2020 07:56 PM
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.
09-09-2020 09:28 PM
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
09-09-2020
11:01 PM
- last edited on
05-13-2025
01:10 PM
by
Content Cleaner
No, a state machine only requires a single loop. You can learn more here: https://www.ni.com/en/support/documentation/supplemental/16/simple-state-machine-template-documentat...