|
Re: turning a push button into a switch
I attached the code we made this year. To use it, just put it in a vi, connect up your momentary button and "switched" output, and then make a shift register and wire that up to the top. The shift register is outside the vi so we can use the same vi many times (if it were inside, the shift register would maintain its values from call to call, not just from loop to loop.)
The problem with your program is that if you press the button for more than 10 ms, it will change twice. My program waits until the button then gets unpressed before going back to the "ready to receive button" state.
I have no idea why your code would switch when you're not pressing the button if that's the actual way you coded it.
My vi works fine in teleop; there's a 20ms loop in teleop and your code has a 10ms loop; it's not a big difference. The 20ms actually helps debounce the switch for us.
NOTE: This code is untested in the real world - you might have to do something to debounce switches. I did test it in the vi with the front panel controls though.
EDIT: Added bundle/unbundle to code to have only one shift register.
Last edited by WizenedEE : 04-02-2011 at 23:34.
|