View Single Post
  #2   Spotlight this post!  
Unread 17-02-2014, 19:33
MathMaven MathMaven is offline
Registered User
AKA: Elisha Sword
FRC #3175 (Knight Vision)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Michigan
Posts: 50
MathMaven is on a distinguished road
Re: How to program a toggle switch to stop a motor from spinning..?

The programming is simple. The idea is that a switch will return either a true value or a false value corresponding to whether the switch is being pressed at the moment.

You want the motor to operate normally when the switch is returning false (is not being pressed), and to be allowed to move only backward when the switch is returning true (is being pressed).

I would implement this knowledge as follows:

Code:
if ( ![switch name here].Get()  )
{
    /* control the motor normally */
}
else
{
    if ( [motor name here].Get() > 0 ) // or < 0; test to figure out!
    {
        [motor name here].Set(0); // necessary: otherwise motor will continue 
                                  // at whatever speed you left it at
    }
}
Naturally, use the syntax of whatever programming language you're using.

I can't help you with the wiring, since I don't know too much about that stuff.
__________________
—Elisha Sword

2010–13: FRC Team 3175 (Knight Vision), student, lead programmer
2012–13: FRC Team 3175 (Knight Vision), lead website designer
2014: FRC Team 3175 (Knight Vision), programming mentor

“Who has not been amazed to learn that the function y = e^x, like a phoenix rising from its own ashes, is its own derivative?”
—Francois le Lionnais
Reply With Quote