LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to perform a single action within a while loop

I want to switch a motor on or off within a while loop. When I put the switch command into the loop the command will be sent to the motor as often as the loop is running. But I need it only one time. Can somebody help me? Thanks
0 Kudos
Message 1 of 5
(3,088 Views)
Well, the obvius answer is to not put thing inside a while loop that shouldn't be run more
then once. But to answer your question...

You need some kind of test inside the while loop, to determine wheter or not the motor
should be switched. Then put the "motor on" vi inside a case and wire it to the test.
What the test should be depends on where in the loop it needs to be done:

1) At a specific loop number: Set a test on whether i=n where n is the loop number where
you want the switch flicked.

2) At a point determined by an other thing, and then not again: Put the "motor on" vi
inside a case and wire it to a boolean control e.g. "motor on?". When the motor is to be
turned on set the boolean to true (causing the VI to be called). Right after this you

reset the boolean to false, and the vi is not called again. This aproach has the advantage
that you can switch more then one time, if you need that...

Best regards

Casper Angelo


ruedigerkramer wrote:
> I want to switch a motor on or off within a while loop. When I put the
> switch command into the loop the command will be sent to the motor as
> often as the loop is running. But I need it only one time. Can
> somebody help me? Thanks
Message 2 of 5
(3,088 Views)
Nice and easy, I took the second way. Thank you!
0 Kudos
Message 3 of 5
(3,088 Views)
Hi,

The easiest way is to make a shift register. Wire a boolean TRUE to it, at
the outside of the while.

If you have a button to trigger the start, AND it with the value from the
shift register.

In the case that starts the motor (the TRUE case), wire a FALSE to the right
end of the shift register. In the FALSE state of the case, wire the input
value to the output value.

Regards,

Wiebe.

"ruedigerkramer" wrote in message
news:5065000000080000002A690000-1031838699000@exchange.ni.com...
> I want to switch a motor on or off within a while loop. When I put the
> switch command into the loop the command will be sent to the motor as
> often as the loop is running. But I need it only one time. Can
> somebody help me? Thanks
Message 4 of 5
(3,088 Views)
Thanks. It works fine. Rüdiger
0 Kudos
Message 5 of 5
(3,088 Views)