edu.wpi.first.wpilibj.buttons
Class Button

java.lang.Object
  extended by edu.wpi.first.wpilibj.buttons.Button
All Implemented Interfaces:
SmartDashboardData
Direct Known Subclasses:
AnalogIOButton, DigitalIOButton, InternalButton, JoystickButton, NetworkButton

public abstract class Button
extends java.lang.Object
implements SmartDashboardData

This class provides an easy way to link commands to 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. It is encouraged that teams write a subclass of Button if they want to have something unusual (for instance, if they want to react to the user holding a button while the robot is reading a certain sensor input). For this, they only have to write the get() method to get the full functionality of the Button class.

Author:
Joe Grinstead

Nested Class Summary
 class Button.ButtonScheduler
          An internal class of Button.
 
Constructor Summary
Button()
           
 
Method Summary
abstract  boolean get()
          Returns whether or not the button is pressed.
 NetworkTable getTable()
          Returns the NetworkTable associated with the data.
 java.lang.String getType()
          Returns the type of the data.
 void whenPressed(Command command)
          Starts the given command whenever the button is newly pressed.
 void whenReleased(Command command)
          Starts the command when the button is released
 void whileHeld(Command command)
          Constantly starts the given command while the button is held.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Button

public Button()
Method Detail

get

public abstract boolean get()
Returns whether or not the button is pressed. This method will be called repeatedly a command is linked to the Button.

Returns:
whether or not the button is pressed.

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

getType

public java.lang.String getType()
Description copied from interface: SmartDashboardData
Returns the type of the data. This is used by the SmartDashboard on the desktop to determine what to do with the table returned by getTable().

For instance, if the type was "Button", then the SmartDashboard would show the data as a button on the desktop and would know to look at and modify the "pressed" field in the NetworkTable returned by getTable().

Specified by:
getType in interface SmartDashboardData
Returns:
the type of the data

getTable

public NetworkTable getTable()
Description copied from interface: SmartDashboardData
Returns the NetworkTable associated with the data. The table should contain all the information the desktop version of SmartDashboard needs to interact with the object. The data should both keep the table up-to-date and also react to changes that the SmartDashboard might make.

For instance, the SendablePIDController will put its p, i and d values into its table and will change them if the table receives new values.

This method should return the same table between calls

Specified by:
getTable in interface SmartDashboardData
Returns:
the table that represents this data