View Single Post
  #3   Spotlight this post!  
Unread 19-03-2012, 15:41
Sconrad Sconrad is offline
Registered User
AKA: Connor Young
FRC #0122 (NASA Knights)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2011
Location: Yorktown
Posts: 40
Sconrad is an unknown quantity at this point
Re: Need serious help with coding!!

Quote:
Originally Posted by kinganu123 View Post
a basic code would be
Code:
if(joystick.getRawButton(4)
     jaguar.set(1);
else if(joystick.getRawButton(5)
     jaguar.set(-1);
else
     jaguar.set(0);
Note: This will not create a toggle effect. If 4 is pressed, the motor will go forward and if 5 is pressed the motor will go in reverse, but it will not continue to go in that direction if you let go of the button. However, this is a good, simple solution to the problem you are facing. One thing to note about how this code will perform, if both buttons are pressed, the jaguar will go forward. One way to fix this is to replace the first line with
Code:
if(joystick.getRawButton(4) && !joystick.getRawButton(5))
It is a little bit longer, but will protect you from accidentally going in the wrong direction should you hit both buttons in the heat of competition. In order to have a true toggle effect, you will probably need a limit switch or potentiometer or other sensor to tell you when you are done going up or done going down. Hope this helps!
Reply With Quote