LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

One button to initiate and terminate a while loop

Hi,

 

I need to use one button to start AND end a while loop.

 

Starting it isnt a problem, in my main while loop I have the button hooked up to a case structure and when its pushed the case structure goes off, and the sub-while loop inside the case structure starts.

 

But then if I release the button, I want the while loop to stop running.

 

Is there any way to do this?  I know it could easily be done with 2 buttons (one in the main while loop hooked up to the case structure and one in the sub-while loop to end it) but is there any way to do it with one?  Its a hastle to have 2 buttons for the purpose im using this for.
Thanks
Raman
0 Kudos
Message 1 of 8
(4,705 Views)

Hello... You can use the inverse input of the same button to stop by using the property node or local variable.....

 

 

0 Kudos
Message 2 of 8
(4,696 Views)

Hi !

I've attached the solution !!!

It's not very diffivult to understand but if you have problems please don't hesitate to comment here.24268i192CD219EF83F28D

P.D:don't forget Kudos 🙂

0 Kudos
Message 3 of 8
(4,683 Views)

 


@kklvuyovb wrote:

 

I need to use one button to start AND end a while loop.

 

Starting it isnt a problem, in my main while loop I have the button hooked up to a case structure and when its pushed the case structure goes off, and the sub-while loop inside the case structure starts.

 

But then if I release the button, I want the while loop to stop running.

 

Is there any way to do this?  I know it could easily be done with 2 buttons (one in the main while loop hooked up to the case structure and one in the sub-while loop to end it) but is there any way to do it with one?  Its a hastle to have 2 buttons for the purpose im using this for.
Thanks
Raman

 

Raman,

 

You might want to redesign your program layout from scratch, because what you are trying to do is probably misguided. It is typically not a good idea to stack interactive while loops. Take two steps back and think about the overall program flow.

 

What you need is a simple state machine with one global loop, the code of your inner while loop is then just one of the states of the outer while loop.

 

Can you attach some of your code so we get a better idea what you are trying to do. What's happening in the inner loop?

 

What is your LabVIEW version?

 

 


 

@jordi wrote:

I've attached the solution !!!

It's not very diffivult to understand but if you have problems please don't hesitate to comment here.

 


 

This is not very good code and just complicated the overall program design. It also needs at least a wait in the FALSE case else it consumes 100% of the CPU while not doing anything useful.

 

 

Message 4 of 8
(4,666 Views)

Yes, I agree with you.

A fast solution for that could be the following...

 24282i35452513320B9C62

0 Kudos
Message 5 of 8
(4,650 Views)

It's still not good, because the VI cannot be stopped with the stop butten while the inner loop is executing.

 

Here's what I meant (LV8.0).

(Even better would be an event structure, switching the timeout from infinity to a finite value and vice versa if the boolean is operated)

0 Kudos
Message 6 of 8
(4,642 Views)

 


altenbach wrote:

(Even better would be an event structure, switching the timeout from infinity to a finite value and vice versa if the boolean is operated)


Here's an example for that.

 

0 Kudos
Message 7 of 8
(4,637 Views)

Another solution is to use two while loops.  One to wait for the button to be pressed in order to start the program.  The other is to run the program itself.

 

24332i8A46A5904186DD5F

- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 8
(4,580 Views)