RobotCore
Robot Core Documentation
Public Member Functions | List of all members
edu.wpi.first.wpilibj2.command.button.Button Class Reference
Inheritance diagram for edu.wpi.first.wpilibj2.command.button.Button:
edu.wpi.first.wpilibj2.command.button.Trigger edu.wpi.first.wpilibj2.command.button.InternalButton edu.wpi.first.wpilibj2.command.button.JoystickButton

Public Member Functions

 Button ()
 
 Button (BooleanSupplier isPressed)
 
Button whenPressed (final Command command, boolean interruptible)
 
Button whenPressed (final Command command)
 
Button whenPressed (final Runnable toRun, Subsystem... requirements)
 
Button whileHeld (final Command command, boolean interruptible)
 
Button whileHeld (final Command command)
 
Button whileHeld (final Runnable toRun, Subsystem... requirements)
 
Button whenHeld (final Command command, boolean interruptible)
 
Button whenHeld (final Command command)
 
Button whenReleased (final Command command, boolean interruptible)
 
Button whenReleased (final Command command)
 
Button whenReleased (final Runnable toRun, Subsystem... requirements)
 
Button toggleWhenPressed (final Command command, boolean interruptible)
 
Button toggleWhenPressed (final Command command)
 
Button cancelWhenPressed (final Command command)
 
- Public Member Functions inherited from edu.wpi.first.wpilibj2.command.button.Trigger
 Trigger (BooleanSupplier isActive)
 
 Trigger ()
 
boolean get ()
 
Trigger whenActive (final Command command, boolean interruptible)
 
Trigger whenActive (final Command command)
 
Trigger whenActive (final Runnable toRun, Subsystem... requirements)
 
Trigger whileActiveContinuous (final Command command, boolean interruptible)
 
Trigger whileActiveContinuous (final Command command)
 
Trigger whileActiveContinuous (final Runnable toRun, Subsystem... requirements)
 
Trigger whileActiveOnce (final Command command, boolean interruptible)
 
Trigger whileActiveOnce (final Command command)
 
Trigger whenInactive (final Command command, boolean interruptible)
 
Trigger whenInactive (final Command command)
 
Trigger whenInactive (final Runnable toRun, Subsystem... requirements)
 
Trigger toggleWhenActive (final Command command, boolean interruptible)
 
Trigger toggleWhenActive (final Command command)
 
Trigger cancelWhenActive (final Command command)
 
Trigger and (Trigger trigger)
 
Trigger or (Trigger trigger)
 
Trigger negate ()
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Button() [1/2]

edu.wpi.first.wpilibj2.command.button.Button.Button ( )

Default constructor; creates a button that is never pressed (unless Button#get() is overridden).

◆ Button() [2/2]

edu.wpi.first.wpilibj2.command.button.Button.Button ( BooleanSupplier  isPressed)

Creates a new button with the given condition determining whether it is pressed.

Parameters
isPressedreturns whether or not the trigger should be active

Member Function Documentation

◆ cancelWhenPressed()

Button edu.wpi.first.wpilibj2.command.button.Button.cancelWhenPressed ( final Command  command)

Cancels the command when the button is pressed.

Parameters
commandthe command to start
Returns
this button, so calls can be chained

◆ toggleWhenPressed() [1/2]

Button edu.wpi.first.wpilibj2.command.button.Button.toggleWhenPressed ( final Command  command)

Toggles the command whenever the button is pressed (on then off then on). The command is set to be interruptible.

Parameters
commandthe command to start
Returns
this button, so calls can be chained

◆ toggleWhenPressed() [2/2]

Button edu.wpi.first.wpilibj2.command.button.Button.toggleWhenPressed ( final Command  command,
boolean  interruptible 
)

Toggles the command whenever the button is pressed (on then off then on).

Parameters
commandthe command to start
interruptiblewhether the command is interruptible

◆ whenHeld() [1/2]

Button edu.wpi.first.wpilibj2.command.button.Button.whenHeld ( final Command  command)

Starts the given command when the button is first pressed, and cancels it when it is released, but does not start it again if it ends or is otherwise interrupted. The command is set to be interruptible.

Parameters
commandthe command to start
Returns
this button, so calls can be chained

◆ whenHeld() [2/2]

Button edu.wpi.first.wpilibj2.command.button.Button.whenHeld ( final Command  command,
boolean  interruptible 
)

Starts the given command when the button is first pressed, and cancels it when it is released, but does not start it again if it ends or is otherwise interrupted.

Parameters
commandthe command to start
interruptiblewhether the command is interruptible
Returns
this button, so calls can be chained

◆ whenPressed() [1/3]

Button edu.wpi.first.wpilibj2.command.button.Button.whenPressed ( final Command  command)

Starts the given command whenever the button is newly pressed. The command is set to be interruptible.

Parameters
commandthe command to start
Returns
this button, so calls can be chained

◆ whenPressed() [2/3]

Button edu.wpi.first.wpilibj2.command.button.Button.whenPressed ( final Command  command,
boolean  interruptible 
)

Starts the given command whenever the button is newly pressed.

Parameters
commandthe command to start
interruptiblewhether the command is interruptible
Returns
this button, so calls can be chained

◆ whenPressed() [3/3]

Button edu.wpi.first.wpilibj2.command.button.Button.whenPressed ( final Runnable  toRun,
Subsystem...  requirements 
)

Runs the given runnable whenever the button is newly pressed.

Parameters
toRunthe runnable to run
requirementsthe required subsystems
Returns
this button, so calls can be chained

◆ whenReleased() [1/3]

Button edu.wpi.first.wpilibj2.command.button.Button.whenReleased ( final Command  command)

Starts the command when the button is released. The command is set to be interruptible.

Parameters
commandthe command to start
Returns
this button, so calls can be chained

◆ whenReleased() [2/3]

Button edu.wpi.first.wpilibj2.command.button.Button.whenReleased ( final Command  command,
boolean  interruptible 
)

Starts the command when the button is released.

Parameters
commandthe command to start
interruptiblewhether the command is interruptible
Returns
this button, so calls can be chained

◆ whenReleased() [3/3]

Button edu.wpi.first.wpilibj2.command.button.Button.whenReleased ( final Runnable  toRun,
Subsystem...  requirements 
)

Runs the given runnable when the button is released.

Parameters
toRunthe runnable to run
requirementsthe required subsystems
Returns
this button, so calls can be chained

◆ whileHeld() [1/3]

Button edu.wpi.first.wpilibj2.command.button.Button.whileHeld ( final Command  command)

Constantly starts the given command while the button is held.

Command#schedule(boolean) will be called repeatedly while the button is held, and will be canceled when the button is released. The command is set to be interruptible.

Parameters
commandthe command to start
Returns
this button, so calls can be chained

◆ whileHeld() [2/3]

Button edu.wpi.first.wpilibj2.command.button.Button.whileHeld ( final Command  command,
boolean  interruptible 
)

Constantly starts the given command while the button is held.

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

Parameters
commandthe command to start
interruptiblewhether the command is interruptible
Returns
this button, so calls can be chained

◆ whileHeld() [3/3]

Button edu.wpi.first.wpilibj2.command.button.Button.whileHeld ( final Runnable  toRun,
Subsystem...  requirements 
)

Constantly runs the given runnable while the button is held.

Parameters
toRunthe runnable to run
requirementsthe required subsystems
Returns
this button, so calls can be chained

The documentation for this class was generated from the following file: