LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to automatically off the push button

Solved!
Go to solution

how can i set the push button to be off automatically after meet certain condition.

i attached simple example just to represent this problem

 

0 Kudos
Message 1 of 14
(8,701 Views)

how about this?

untitled.PNG

Best regards,
Krispiekream
Message 2 of 14
(8,698 Views)
no, the button wont off...the loop continuously runs
0 Kudos
Message 3 of 14
(8,684 Views)

I think the user is actually asking how to stop the outer loop if the Stop button is pressed or the iteration count reaches 10.

 

 

To poster: You need an OR condition on the outer loop's conditional terminal. One OR input comes from the Stop button. The other comes from the case structure. In the False case you wire out a False Boolean constant. In the True part you wire out a True. You could also wire the OR input to the Boolean control directly since this amounts to the same thing.

 

Code comments:

  • Do not create greedy loops. Use a small delay so you don't starve the CPU.
  • I think you want the inner loop's condition terminal to be "Continue if True".
  • You can use the Increment function rather than using an Add function and a constant of 1.
  • You don't actually need the inner loop at all. You can use a Feedback Node.
Message 4 of 14
(8,682 Views)

smercurio_fc wrote:

I think the user is actually asking how to stop the outer loop if the Stop button is pressed or the iteration count reaches 10.

 

 

To poster: You need an OR condition on the outer loop's conditional terminal. One OR input comes from the Stop button. The other comes from the case structure. In the False case you wire out a False Boolean constant. In the True part you wire out a True. You could also wire the OR input to the Boolean control directly since this amounts to the same thing.

 

Code comments:

  • Do not create greedy loops. Use a small delay so you don't starve the CPU.
  • I think you want the inner loop's condition terminal to be "Continue if True".
  • You can use the Increment function rather than using an Add function and a constant of 1.
  • You don't actually need the inner loop at all. You can use a Feedback Node.

Adding to these comments it is important to note that if you read the value of a button to control stopping a loop you should always ensure that you read it AFTER you execute all of your code in the loop. If you don't you can easily end up with an "off-by-one" execution since the button will get read very early in the loop iteration and it will use that value when deciding if the loop should exit or not. It won't use the value of the button at that instance in time (end of teh loop iteration).



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 5 of 14
(8,678 Views)

Mark Yedinak wrote:
Adding to these comments it is important to note that if you read the value of a button to control stopping a loop you should always ensure that you read it AFTER you execute all of your code in the loop. If you don't you can easily end up with an "off-by-one" execution since the button will get read very early in the loop iteration and it will use that value when deciding if the loop should exit or not. It won't use the value of the button at that instance in time (end of teh loop iteration).

Yes, and I considered that when making my comments. In this case it obviously didn't matter since the setup of the original VI is such that when the toggle is True it goes into an inner loop, so the outer loop won't stop until the inner loop finishes. Even if the outer loop's stop condition has already been set. That's why I said you could wire the one input of the OR directly to the toggle switch terminal. In general, though, your comment is obviously valid.

 

One additional comment I neglected to include:

 

  • My comments regarding the "Stop if True"/"Continue if True"and the Feedback Node was based on the premise that you're trying to do some sort of counting starting at some point. If that is not the case... then what are you trying to do?
Message 6 of 14
(8,663 Views)

i manage to get the off button done..what i did is i create 2 separated case structure and use local variable to write into the boolean..

thanks for helping

0 Kudos
Message 7 of 14
(8,605 Views)

What? Two separate case structures and a local variable? This is completely unnecessary based on the initial premise!

 

Please post your code so we can see what you're actually trying to do.

0 Kudos
Message 8 of 14
(8,588 Views)

lol.jpg

 

i dont know if i violate the basic labview rules..but at least it works for me..=) this is just an example to switch off the button, the actual program is totally different.

0 Kudos
Message 9 of 14
(8,572 Views)
This seems pretty straight forward. You can directly use a "Switch until released".
0 Kudos
Message 10 of 14
(8,569 Views)