LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

run subvi once when boolean is true

Hi
I have a loop with a few booleans. when boolean1 is checked a subvi should run one time and no more. except when the boolean1 is unchecked and then rechecked.
how can I do that?
0 Kudos
Message 1 of 7
(3,609 Views)
Use a shift register to check the previous state of your boolean. If previous state was False and current state is True, run your sub-VI.
Add a shift register by right-clicking on the left-hand border of the while loop and selecting Add Shift Register. Initialize the shift register to False by wiring a False constant outside of the loop to the left-hand shift-register terminal. Wire the Boolean1 (inside the loop) to the right-hand terminal of the shift register. Your case is controlled by Boolean1 AND NOT left-hand shift-register.
See the attached LabView 7 example.
Message 2 of 7
(3,607 Views)
thank you for your precious help. I tried to work it out with the new event structures but couldn't find a solution.
yves
0 Kudos
Message 3 of 7
(3,607 Views)
To use an event structure...

Create a do loop and wire the stop button (as you did).
Create an event structure inside the do loop.
Right click the event structure and add an event case.
On the left, select the Boolean1 control
On the right, scroll down and select the 'Value Change' event.
Add this event (exit the dialog).
In the event case, place the subvi you wish to call.

Each time the button changes, off to on, or on to off, the subvi will be called once. If you would like to reset the way your boolean button looks on each change you can also create a local variable of Boolean1 and write to it using the OldVal which will be on the left wall of the event structure. I actually like to wire OldVal through a Sequence frame with a small tim
e delay (250ms), then write it to the local variable. This lets the user know they clicked and the click was processed.
0 Kudos
Message 4 of 7
(3,607 Views)
I tried this too. but I just want the subvi run when I click the boolean on. when it's clicked off nothing should happen.
0 Kudos
Message 5 of 7
(3,607 Views)
In the event structure enclose the subVI call with a CASE structure. Wire the selector on the CASE to the NEWVAL terminal on the EVENT structure.

It will only be called when the button/switch goes ON, not when it goes OFF.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 6 of 7
(3,607 Views)
I would like this for version 6.1 if possible.
as i require an inversion of boolean state on one line when the boolean state changes from false to true on another line.
Context: Voice triggered headlights (where other elements also have an effect on the headlights) the headlight turns ON/OFF upon the recognition of a voice command.
0 Kudos
Message 7 of 7
(3,456 Views)