|
Re: Help on programming a limit switch
That attachment works better for viewing.
Your Teleop needs a little work. Your answer approximates what I posted.
The way you set it up, the three case statements will roll the dice for who wins at setting the motor speed. The last one wins, but that doesn't mean the one on the bottom. You need a cascade of wires rather than local variables to do what you are attempting. Local variables should generally be avoided and shouldn't be set all over the place. Local/Global variables are set once, read everywhere.
PS.
Here is your example with some changes to make it a cascade. I also simplified the button check. The picture is your code just with the Case statements replaced by Selects, only because that way every choice can be seen at a glance.
The limit switch values might be different depending on how the limit switch has been wired. There are two choices in the wiring: 1) normally open, 2) normally closed. One way will return a True until it is pressed, the other way will return a False until pressed. After you've wired a limit switch, test it in code to see which value you are getting. In other words, you may have to reverse your True/False cases depending on how the switch has been wired (and don't assume without double checking).
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
Last edited by Mark McLeod : 25-01-2013 at 12:50.
|