LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using a button to start and stop VIs

I am trying to make a guitar effects box inside Labview. I have got a seperate .vi for each effect (be it pitch shifting/delay/distortion etc). I want to make a menu with buttons which when pressed will run each effect. Then if the button to start a different effect is pressed I want the one that was running previously to stop running.

See the attached VI to see where I have got to. The VI for each effect currently runs when the start button is pressed however when the other button is pressed the first one is still running.

Would anyone be able to help out?

Thanks

0 Kudos
Message 1 of 9
(4,772 Views)

Hi James,

 

those subVIs are missing…

 

- Right now your VI is only able to handle each button once as there is no loop in the VI.

- I guess there are loops inside those subVIs: get rid of them - or find a way to stop those subVIs from your main VI…

- Why do you need two event structures? One should be enough!

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 9
(4,767 Views)

Hi James, 

 

I agree with GerdW, one event structure should be enough, just put two events in it. 

 

It would also be useful to see what is in the subVIs. Would you like the effect of what the subVIs do to be stopped once another event happens? Maybe you could have a reinitialise values subVI inside the sequence structures? 

 

There is some extra info on event structures here and here

 

Many Thanks, 

 

Riley Ilieva

Applications Engineer

National Instruments 

 

 

0 Kudos
Message 3 of 9
(4,725 Views)

I think the best thing to do for you is to use the "File-->New..." menu option to create a new "Producer/Consumer Design Pattern (Events)" design pattern from the templates.

 

New Producer Consumer Design Pattern (Events).pngOnce you have that, you'll want to add an event case for each of your button value change events in the event structure of the top producer loop. The bottom loop can look for elements in the string queue. Based on the string popped off from the queue, you can call whatever SubVI you need.

 

In your SubVI, you'll need to monitor the contents of the string queue for any new values (or error) so that the SubVI can return. Only when the SubVI returns is when the bottom consumer loop can continue to run (or stop) . Here's an example (the loop in yellow shows what the code in the SubVI could look like):

 

Start and Stop Button Test - Producer Consumer.png

 

Hope this helps,

Pang

Feel free. Contact me for anything more,
    Pang

You too can be LabVIEW Awesome!
0 Kudos
Message 4 of 9
(4,711 Views)

I didn't include the subVIs as I thought that this isn't a problem specific to those subVIs, I'd like it to work for any subVIs as I will add more later on. The subVIs currently run continuously for an infinite amount of time doing whichever effect it is they do. The idea was to have a start button for each subVI which when pressed will run that subVI. This subVI will then run forever until the start button of another subVI is pressed. Then this new subVI will start to run and the previous one is stopped.

 

From the attached file in the topic header I have managed to get the subVIs to start running when the buttons are pressed however I believe that when a second button is pressed the previous subVI still runs. So how can the subVIs be stopped by a button press, does it need to be stopped from inside the subVI? And then how would a start button from one subVI also stop the one that is running?

 

I hope this helps to better explain the problem. Thanks

0 Kudos
Message 5 of 9
(4,692 Views)

From what we can see by looking at your code, you need to first start with a few simple LabVIEW tutorials and grasp the basics of dataflow. In your case, the VI runs exactly once (continuous run mode is a debugging tool, not a way to run a VI) and the VI can only complete once both event structures have fired.

 

I assume that you want to be able to apply multiple effects at the same time and that "no effect" is also just one of the posibilities.

 

So, all the VI needs to contain is a toplevel while loop that continuously reads the input signal and generates an output from it. In between input and output add your processing steps (e.g. with a series of case structures), each tied to a button (switch action, learn about the various mechanical action settings!), and each simply wired across in the FALSE case while containing the processing in the TRUE case. This should get you started. We can add more advanced architectures later.

 

Of course you could complicate it a little bit by using latch action booleans and toggle with each press, but let's keep it simple initially.

0 Kudos
Message 6 of 9
(4,682 Views)

wrote:

We can add more advanced architectures later.


Not to hijack the question too much, but would this be a good place to use LabVIEW's OOP where an instrument class could be operated on by various effects? 


0 Kudos
Message 7 of 9
(4,677 Views)

Well, there are no complicated "instruments", just "audio data in ---> audio data out" for each processing step, so I would keep it simple. But yes, anything can be done.

 

Of course the entire things needs to be designed to operate in real time, so all processing needs to fit in the time constraints of the continuous IO.

0 Kudos
Message 8 of 9
(4,670 Views)

Perhaps you want something like this.  It creates a list of effects from VIs in the Effects folder.  Then calls the VIs dymanically based on what's selected (0 or more items) in the listbox.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 9 of 9
(4,633 Views)