|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: Help programming joystick buttons
Quote:
if you could show us an example of a code using getRawButton that would be very helpful. |
|
#2
|
||||
|
||||
|
Re: Help programming joystick buttons
Quote:
Joystick j = new Joystick(1); JoystickButton a = new JoystickButton(j,1); a.whileHeld(new YourCommand()); in command based or Joystick j = new Joystick(1) if(j.getRawButton(1)){ do stuff } in iterative. both will run when A is pressed |
|
#3
|
||||||
|
||||||
|
Re: Help programming joystick buttons
Quote:
Here is an example of using getRawButton to switch between tank drive and arcade drive when the trigger (button one) on the left joystick is pressed. Code:
public void operatorControl() {
chassis.setSafetyEnabled(true);
if (leftStick.getRawButton(1))
{
chassis.tankDrive(leftStick, rightStick);
Timer.delay(0.01);
}
else
{
chassis.arcadeDrive(leftStick);
}
}
|
|
#4
|
|||
|
|||
|
Re: Help programming joystick buttons
Have you heard about command based programming? It is a lot cleaner and will help you avoid creating hundreds (okay, not hundreds) of "else if" blocks and actually set up a polymorphic structure and abstracting your code. It's a specifically tailored design pattern. It's probably too late now, but it's something you should consider next year: http://firstforge.wpi.edu/sf/docman/...tation/doc1297
Last edited by arithehun : 11-02-2013 at 02:27. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|