Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   How to program a button this way? (http://www.chiefdelphi.com/forums/showthread.php?t=113568)

ctccromer 15-02-2013 14:32

How to program a button this way?
 
Rather than program "do [this] when the button is pressed down, do [that] when it's not pressed down", I want to program "do [this] when it's pressed, then do [that] when the same button's pressed again" and alternate between them. It would be really easy in a text based language but I'm a LabVIEW noob and don't know how to do it :/

I'm working with pneumatics. Basically I just need to give one Vi a value of 0 and another Vi a value of 1 when a button is pressed, and leave it that way even when I let go of the button. Then, next time I press the button, switch the two values. Then next time, switch them back, etc.

Pneumatics start retracted. Push button x to push the pneumatic arms out. Push button x again to pull the pneumatic arms back in

Omar 15-02-2013 14:44

Re: How to program a button this way?
 
Do a search for "toggle" and you will find about a dozen ways to toggle between two states.

http://www.chiefdelphi.com/forums/sh...ghlight=toggle

Ether 15-02-2013 15:10

Re: How to program a button this way?
 
Quote:

Originally Posted by ctccromer (Post 1233905)
...

When you encounter a problem like this in LabVIEW, and it seems like "Hmm. I can't be the first person to want to do this. I'm sure somebody has already figured this out"... then go to:

http://team358.org/files/programming...2009-/LabVIEW/

... and scroll down to "Common Robot Operations"



bvisness 15-02-2013 20:56

Re: How to program a button this way?
 
Quote:

Originally Posted by Ether (Post 1233925)
When you encounter a problem like this in LabVIEW, and it seems like "Hmm. I can't be the first person to want to do this. I'm sure somebody has already figured this out"... then go to:

http://team358.org/files/programming...2009-/LabVIEW/

... and scroll down to "Common Robot Operations"



358's solution works, but our team's method is a bit simpler.

EDIT: It's remarkably similar to the solution in the thread Omar posted above. Take your pick!

josneville 16-02-2013 00:47

Re: How to program a button this way?
 
1 Attachment(s)
Its called a feedback loop. It looks like this:

Greg McKaskle 16-02-2013 07:56

Re: How to program a button this way?
 
Focussing on the original problem, I'm curious what solution you would have done in a text language? I ask this because this sort of thing comes up often as folks are just learning to program or are learning a new language, and I'm wanting to make sure that I understand the things that kept you from finding the solution.

Greg McKaskle

ctccromer 16-02-2013 19:05

Re: How to program a button this way?
 
Quote:

Originally Posted by Greg McKaskle (Post 1234237)
Focussing on the original problem, I'm curious what solution you would have done in a text language? I ask this because this sort of thing comes up often as folks are just learning to program or are learning a new language, and I'm wanting to make sure that I understand the things that kept you from finding the solution.

Greg McKaskle

In a text language, I'd just make a boolean PneumaticsRetracted or something like that. Then when I press the right button, if the bool is true, do one thing, if it's false, do the other. And in both, change the bool's value to the opposite of course

Greg McKaskle 17-02-2013 07:50

Re: How to program a button this way?
 
In the text language, the Boolean variable would need to be static or global in order to keep its value from call to call. That serves the same purpose as the feedback node. It remembers state data in a scope that is longer lived than the function call.

In a text language, the local variables, and in LV, the wires, have a short-lived scope that is cleared each time the function is called. They are temporaries.

FYI, you can actually make global variables in LV too, so if you don't get the hang of the feedback node, try with globals. But the feedback node or shift registers are a somewhat safer and more controlled language feature, like static local variables are in C, etc. So it is good to learn how to use them.

Greg McKaskle


All times are GMT -5. The time now is 12:13.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi