LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make a button to stop and run a while loop?

Hi all,

I am a beginner in the Labview. I did a program that contains a while loop, its stop condition is connected to button. I selected “switch when pressed” to be the operation of this button. Our teacher asked us to make this button stops the loop if it is pressed and its name is converted to run instead of stop. And if it is pressed then again it starts the loop from the point it stopped in.

Can anybody help me, please?

0 Kudos
Message 1 of 11
(7,250 Views)
First, please use a smaller font when composing your messages.
 
You will need two while loops.  An inner loop which has its stop terminal attached to the stop button.  Put that in the False case of a case structure.  Wire a local variable of that stop button to the case selector of the case structure.  Put the case selector inside another while loop which is the one that keeps the program running no matter what the state of the original Stop button.  You will need a master stop button to stop the outer loop when you are ready to end the whole program.  Don't forget to put small millisecond waits in each of the loops so that the loops don't eat up all the CPU resources.
 
For that stop button, you could rename the True title to Run, so that when it is pressed to stop the inner loop, the button will show the word Run.  Pressing it again pops it back out, allows the false case to execute and the innermost while loop to run.
 
You could also change the words on the buttons by using property nodes.
Message 2 of 11
(7,210 Views)
Thank you very much, I will try that
0 Kudos
Message 3 of 11
(7,197 Views)

Look at this Vi I put together. Perhaps it will give you ideas. Thanks.

 

~Papa

0 Kudos
Message 4 of 11
(7,194 Views)

Pkone,

That's a good use of the event structure.  But I wonder why you did an exclusive OR with true wired to the continue terminal?  One step simpler would have been to do a NOT operation.  Simplest yet would have been to wire it to a stop terminal with False in the Run/Stop and timeout events and a True constant in the Exit (M??) event.

0 Kudos
Message 5 of 11
(7,187 Views)

Dear Ravens Fan,

I tried to do what you suggest, but since  I am as I said a beginner I have errors.   I attached the VI.

0 Kudos
Message 6 of 11
(7,174 Views)
I think you need to take some Labview tutorials.  Your errors shown are broken wires.  If you click on the broken Run arrow, it will you a list of errors and the reasons why.  You are trying to wire things in ways that won't work.  Whatever you wire to the case selector node (green ?) must come from outside of the case.  Your local variable for Stop should be outside the case structure and in the outermost loop.  Right click on it and select "Change to Read"  Then wire it into the green ?
Since your button is a boolean, it can only have 2 cases.  True and False.  Your one case is false, but your other case should be True, not "Run".
Take care of these and your code should work.  Then it would be a matter of cleaning up the format of your buttons by right clicking on them and selecting Properties.  Change the pressed label to "Run" instead of "Stop".
0 Kudos
Message 7 of 11
(7,153 Views)
You can use a Text button to change the texts without having to using the property nodes. Smiley Wink
- Partha ( CLD until Oct 2027 🙂 )
0 Kudos
Message 8 of 11
(7,138 Views)
see this post for some places to start

Paul
0 Kudos
Message 9 of 11
(7,135 Views)
sorry, above reply posted to wrong thread

Paul
0 Kudos
Message 10 of 11
(7,133 Views)