How to program Xbox Triggers (Java)

I was wondering how to set up the Xbox controller triggers so that I may control the speed of the motors depending on where the triggers are positioned. Thanks for the help!
~Robert Byrd

We have a joysticks class for our Xbox controllers. Uses every button on the controller. Feel free to use whatever you want.

Since the triggers are a double value, you just input that into your motor output. Example:
TalonSRXObj.set(percentOutput, joystick1.leftTrigger);

There are a couple of ways you can do this, if you are using the XboxController class, you can use the getTriggerAxis(Hand hand) method, where hand is either Hand.kLeft or Hand.kRight depending on which trigger you want.

eg, get the right trigger value

  XboxController xb = new XboxController(0);
  double triggerValue = xb.getTriggerAxis(Hand.kLeft);

You can then pass that information onto your motor controller.
eg, if you use a PWM Spark

spark.set(triggerValue);

You’re using public member variables!?!? I won’t tell. :shushing_face:

1 Like

Haha I’m too lazy. It’s just easier.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.