Use joystick as button?

I want to use a Joystick as a button by setting a threshold, at which point it will run a command. What’s they best way to accomplish this? I was going to write a custom trigger, but I can’t find a tutorial and I’m getting an error (described below). I guess I could just put an if statement in the command.

Trigger Code:

package frc.robot;
import edu.wpi.first.wpilibj.buttons.Trigger;

/** Add your docs here. */
public class TriggerL2Button extends Trigger {
  public boolean get() {
    return RobotContainer.controller.getRawAxis(3) > 0.5;

Relevant Code:

public static final TriggerL2Button intakeButton = new TriggerL2Button();
public static final TriggerR2Button flywheelButton = new TriggerR2Button();

Error-ing Code:

private void configureButtonBindings() {


The method whileActive(Command) in the type Trigger is not applicable for the arguments (SpinIntakeWheel)Java(67108979)

I don’t understand why this results in an error because SpinIntakeWheel is a command and TriggerL2Button extends Trigger. I generated the trigger using the old trigger template and added the old WPILib library, but it’s the same as what’s shown in the current docs.

Link to project: FRC-Code-2022/src/main/java/frc/robot at fixingQuickTestCode · frc6506/FRC-Code-2022 · GitHub

Update: I get a similar error if I create an instance of a Command without setting it to anything and pass it to whileActive.

At a glance, my guess is an issues with the new vs old command-based frameworks.

You’re using edu.wpi.first.wpilibj.buttons.Trigger, which takes in a edu.wpi.first.wpilibj.command.Command

I think you want edu.wpi.first.wpilibj2.command.button.Trigger which takes in a edu.wpi.first.wpilibj2.command.Command

It looks like you shouldn’t need to change much (if any) code other than the import statement in your


I just reached the same conclusion.

After you change the import, you will need to update lines 102-103 of RobotContainer from




EDIT: I just opened a PR with my changes: Fix Xbox controller triggers by MarkGhebrial · Pull Request #7 · frc6506/FRC-Code-2022 · GitHub


Thanks, that fixed it!


Thanks for catching the whileActiveContinuous bit too.

1 Like

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