Class Button
java.lang.Object
edu.wpi.first.wpilibj2.command.button.Trigger
edu.wpi.first.wpilibj2.command.button.Button
- All Implemented Interfaces:
BooleanSupplier
- Direct Known Subclasses:
InternalButton
,JoystickButton
,NetworkButton
,POVButton
@Deprecated public class Button extends Trigger
Deprecated.
Replace with
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.
-
Constructor Summary
Constructors Constructor Description Button()
Deprecated.Replace withnew Button(() -> false)
.Button(BooleanSupplier isPressed)
Deprecated.Replace with Trigger. -
Method Summary
Modifier and Type Method Description Button
cancelWhenPressed(Command command)
Deprecated.Instead, pass this as an end condition toCommand.until(BooleanSupplier)
.Button
toggleWhenPressed(Command command)
Deprecated.Replace withTrigger.toggleOnTrue(Command)
Button
whenHeld(Command command)
Deprecated.Replace withTrigger.whileTrue(Command)
Button
whenPressed(Command command)
Deprecated.Replace withTrigger.onTrue(Command)
Button
whenPressed(Runnable toRun, Subsystem... requirements)
Deprecated.Replace withTrigger.onTrue(Command)
, creating the InstantCommand manuallyButton
whenReleased(Command command)
Deprecated.Replace withTrigger.onFalse(Command)
Button
whenReleased(Runnable toRun, Subsystem... requirements)
Deprecated.Replace withTrigger.onFalse(Command)
, creating the InstantCommand manuallyButton
whileHeld(Command command)
Deprecated.UseTrigger.whileTrue(Command)
withRepeatCommand
.Button
whileHeld(Runnable toRun, Subsystem... requirements)
Deprecated.UseTrigger.whileTrue(Command)
and construct a RunCommand manuallyMethods inherited from class edu.wpi.first.wpilibj2.command.button.Trigger
and, cancelWhenActive, debounce, debounce, getAsBoolean, negate, onFalse, onTrue, or, toggleOnFalse, toggleOnTrue, toggleWhenActive, whenActive, whenActive, whenInactive, whenInactive, whileActiveContinuous, whileActiveContinuous, whileActiveOnce, whileFalse, whileTrue
-
Constructor Details
-
Button
Deprecated.Replace withnew Button(() -> false)
.Default constructor; creates a button that is never pressed. -
Button
Deprecated.Replace with Trigger.Creates a new button with the given condition determining whether it is pressed.- Parameters:
isPressed
- returns whether or not the trigger should be active
-
-
Method Details
-
whenPressed
Deprecated.Replace withTrigger.onTrue(Command)
Starts the given command whenever the button is newly pressed.- Parameters:
command
- the command to start- Returns:
- this button, so calls can be chained
-
whenPressed
Deprecated.Replace withTrigger.onTrue(Command)
, creating the InstantCommand manuallyRuns the given runnable whenever the button is newly pressed.- Parameters:
toRun
- the runnable to runrequirements
- the required subsystems- Returns:
- this button, so calls can be chained
-
whileHeld
Deprecated.UseTrigger.whileTrue(Command)
withRepeatCommand
.Constantly starts the given command while the button is held.Command.schedule()
will be called repeatedly while the button is held, and will be canceled when the button is released.- Parameters:
command
- the command to start- Returns:
- this button, so calls can be chained
-
whileHeld
Deprecated.UseTrigger.whileTrue(Command)
and construct a RunCommand manuallyConstantly runs the given runnable while the button is held.- Parameters:
toRun
- the runnable to runrequirements
- the required subsystems- Returns:
- this button, so calls can be chained
-
whenHeld
Deprecated.Replace withTrigger.whileTrue(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.- Parameters:
command
- the command to start- Returns:
- this button, so calls can be chained
-
whenReleased
Deprecated.Replace withTrigger.onFalse(Command)
Starts the command when the button is released. The command is set to be interruptible.- Parameters:
command
- the command to start- Returns:
- this button, so calls can be chained
-
whenReleased
Deprecated.Replace withTrigger.onFalse(Command)
, creating the InstantCommand manuallyRuns the given runnable when the button is released.- Parameters:
toRun
- the runnable to runrequirements
- the required subsystems- Returns:
- this button, so calls can be chained
-
toggleWhenPressed
Deprecated.Replace withTrigger.toggleOnTrue(Command)
Toggles the command whenever the button is pressed (on then off then on). The command is set to be interruptible.- Parameters:
command
- the command to start- Returns:
- this button, so calls can be chained
-
cancelWhenPressed
Deprecated.Instead, pass this as an end condition toCommand.until(BooleanSupplier)
.Cancels the command when the button is pressed.- Parameters:
command
- the command to start- Returns:
- this button, so calls can be chained
-