Class Button

java.lang.Object
edu.wpi.first.wpilibj.buttons.Trigger
edu.wpi.first.wpilibj.buttons.Button
All Implemented Interfaces:
Sendable
Direct Known Subclasses:
InternalButton, JoystickButton, NetworkButton, POVButton

public abstract class Button
extends Trigger
This class provides an easy way to link commands to OI inputs.

It is very easy to link a button to a command. For instance, you could link the trigger button of a joystick to a "score" command.

This class represents a subclass of Trigger that is specifically aimed at buttons on an operator interface as a common use case of the more generalized Trigger objects. This is a simple wrapper around Trigger with the method names renamed to fit the Button object use.

This class is provided by the OldCommands VendorDep

  • Constructor Details

  • Method Details

    • whenPressed

      public void whenPressed​(Command command)
      Starts the given command whenever the button is newly pressed.
      Parameters:
      command - the command to start
    • whileHeld

      public void whileHeld​(Command command)
      Constantly starts the given command while the button is held.

      Command.start() will be called repeatedly while the button is held, and will be canceled when the button is released.

      Parameters:
      command - the command to start
    • whenReleased

      public void whenReleased​(Command command)
      Starts the command when the button is released.
      Parameters:
      command - the command to start
    • toggleWhenPressed

      public void toggleWhenPressed​(Command command)
      Toggles the command whenever the button is pressed (on then off then on).
      Parameters:
      command - the command to start
    • cancelWhenPressed

      public void cancelWhenPressed​(Command command)
      Cancel the command when the button is pressed.
      Parameters:
      command - the command to start