![]() |
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 |
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 |
Re: How to program a button this way?
Quote:
http://team358.org/files/programming...2009-/LabVIEW/ ... and scroll down to "Common Robot Operations" |
Re: How to program a button this way?
Quote:
EDIT: It's remarkably similar to the solution in the thread Omar posted above. Take your pick! |
Re: How to program a button this way?
1 Attachment(s)
Its called a feedback loop. It looks like this:
|
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 |
Re: How to program a button this way?
Quote:
|
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