Showing results for 
Search instead for 
Did you mean: 

Time delay while loop before stopping the loop

Go to solution


Hi All,


I modified this code from one of the example in the forum. I forgot which thread. Original file name is "loop speed"


I want to measure pressure and compare with target pressure. Once the pressure reading is higher than the target pressure, I hold the output high for 5 seconds and turn it to low. 


When It goes back to low, I want the to exit the loop or when I pressed the stop button. I do not how to do this one. Please help.





0 Kudos
Message 1 of 7

Hi Havevun,


Try using a case structure with a couple different states. For instance "Measure", "Hold" and "Exit". This way you are only checking for one condition in each state.

0 Kudos
Message 2 of 7

Yeah, you definately want a state machine.  This probably would become very simple when you break down the states properly.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 3 of 7

Hi Gregoryj and Crossruiz,


Thank you it really helps. The logic is cleaner than my previous. 


There is this thing that I need to fix.


Motor is used to increase pressure

Valve is to dump the pressure. 

I used delay to hold thre pressure once it reach the target pressure. (TRUE condition). 


Pressure readings fluctuate.

The problem that I have here is that once the pressure reading is higher than the target. I do not want the code to return back to "False" (pressure reading is lower than target). 


Please advise.



0 Kudos
Message 4 of 7
Accepted by topic author havevun

I can't view your VI (I'm using LV 2014). Please see my attachment for an example. See what happens when you make the value of numeric >= 1. Turn on the highlight execution if it does not make sense.

0 Kudos
Message 5 of 7

Thank you, Gregoryj. 


It works like a charm

0 Kudos
Message 6 of 7
You're welcome. As a side note, it is best practice to type define the enum, so that if you change it, it will update everywhere. I didn't do that here to limit the file dependencies.
0 Kudos
Message 7 of 7