Do you know how to assign a command to a JoystickButton in the OI?
You can do the same using a DigitalIOButton as well.
Code:
Button limitSwitch = new DigitalIOButton(RobotMap.limitSwitch);
and then assign it a command
Code:
limitSwitch.whenPressed(new ReverseMotor());
so then you just have the command reverse the motor.
then do the same with the second limit switch to stop the motor.
then you use a JoystickButton triggered command to move the motor back forward.
If you don't really understand the Command Based Template then I suggest you watch these 6 videos by Brad Miller on the topic(they total about an hour):
FRC 2012 Rapidly creating a robot programl
__________________

Programmer - A creature known for converting Caffeine into Code.
Studying Computer Science @ Louisiana Tech University
Associate Consultant @ Fenway Group
2012-13: 3946 - Head of Programming, Electrical and Web
2014 - 3468 - Programming Mentor
2015 - Present - Lurker