View Single Post
  #11   Spotlight this post!  
Unread 27-01-2014, 15:06
gixxy's Avatar
gixxy gixxy is offline
Programming and Arduino Mentor
AKA: Gustave Michel III
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Ruston, LA
Posts: 207
gixxy is on a distinguished road
Re: How to Program Limit Switches

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