Toggle switch problems

I’ve been working with lab view for maybe a year now and I’ve been talking with a programmer for a couple of months trying to get a toggle switch to work. I have what I believe is correct for the programming wiring in labview. I’ve set up a ref num in begin .vi and set up a back ref to begin .vi in a new vi I made. But yet when I deploy it I can’t control the motor.

Post your code.

What do you mean by a “toggle switch”? I can think of at least three things you might be referring to, and they’re all completely different.

What do you want to do with the switch? Be as specific as you can.

By a toggle switch I mean you press a button on a joystick once and the motor turns on. You press the same button again and it turns off.

http://www.chiefdelphi.com/forums/showpost.php?p=1029709&postcount=2

If you set it up like this, you can make it a SubVI with an input and output instead. This is useful if you want to have multiple toggles in your code, so that your Teleop.vi doesn’t get as cluttered.

Oh wow. ok this is so much more complicated then I’ve been told. I’ve been told by someone on FIRST forums that it was a lot simpler. http://forums.usfirst.org/showthread.php?p=58107#post58107
That was the forum with everything I’ve been using, and what you posted there is so much different then what I’ve seen. :confused:

a much easier way would be to have a local/global variable , and when you click a joystick button, in a case structure read the value, wire it to a not, and write the value to the variable. It is a lot less confusing then the previous posts and just as effective

Actually, the previous post is the more professional way of doing it. Globals and locals, in almost any language, are the least common denominator and often not the best approach. Next time you write a simple expression that has localized state data, try using a shift register. Next time you have an expression needed in multiple places, try using a subVI.

Greg McKaskle

Here are a couple subvi’s we have made to help with these issues.

TON.vi is “Timer On delay” takes a Boolean input and delays TRUE in milli-seconds.
TOF.vi is “Timer Off delay” takes a Boolean input and delays the on to off transition by milliseconds.
TOF_Toggle.vi takes a Boolean input, TOF’s signal and then toggles output state.

In PLC code, TOF is used to de-bounce signals, limit switches. Many game controllers will double trip when pressed or released, using the TOF will mask those events. We typically use 100 ms for the delays for joystick buttons.

All of these do not stall code with waits, it will take a snapshot of current time and set the future time to look for the delay, and are re-entrant mode, so many in the vi will not conflict with each other.

TORC Sub VIs.zip (26 KB)


TORC Sub VIs.zip (26 KB)

lorem3k, in the code you sent me the node right after your button 1 unbundle value what would that be and where would i find it? Anyone can answer if need be. :smiley:

The node with Button 1 going into it is just a SubVi with the code shown above inside. Also, the 4 different images above are the different states of the case structures, you don’t need to put it into the VI 4 times. Sorry for any confusion.

The input and output for the subvi. You connect it to the greater than node. their green, where would i find these??

Right-click on one of the greater than’s terminals and choose Create -> Control. Right-click on one of the constants inside the second case structure (doesn’t matter which) and choose Create -> Indicator. To wire them to have an input and output as a SubVI node, open the front panel of the VI, right-click the icon near the top-right, and choose Patterns -> the one that’s just a square with one vertical line dividing it in half. Click and hold on the left one, drag the mouse to the input button on the front panel, and then click it; and then repeat with the right half and the output indicator. Now the node will have an input and output in Teleop.vi (or wherever you choose to put it), and you simply wire the button to the input side, and the output to whatever case structure you want to control.