stamp.core
Class Button

java.lang.Object
  |
  +--stamp.core.Button

public class Button
extends Object

Push button with auto-repeat and repeat-delay.


Field Summary
static int BUTTON_AUTO_REPEAT
          The button is down and is auto-repeating.
static int BUTTON_DEBOUNCE
          The button has just gone down and we are waiting for the debounce period.
static int BUTTON_DOWN
          The button has just gone down.
static int BUTTON_UP
          The button is currently up.
 int debounceDelay
          The amount of time to debounce when the button goes down.
static int DEFAULT_REPEAT_DELAY
           
static int DEFAULT_REPEAT_RATE
           
 int repeatDelay
          Delay in milliseconds before repeat starts.
 int repeatRate
          Delay in milliseconds between each repetition.
 
Constructor Summary
Button(int portPin, boolean upState)
          Create an instance of the Button class without auto-repeat.
Button(int portPin, boolean upState, int repeatDelay, int repeatRate)
          Create an instance of the Button class with auto-repeat enabled.
 
Method Summary
 boolean buttonDown()
          Check whether the button is down.
 int getState()
          Returns the current state of the button.
 
Methods inherited from class java.lang.Object
equals
 

Field Detail

repeatDelay

public int repeatDelay
Delay in milliseconds before repeat starts.

repeatRate

public int repeatRate
Delay in milliseconds between each repetition.

debounceDelay

public int debounceDelay
The amount of time to debounce when the button goes down. Measured in milliseconds. 25ms is a reasonable value. By default there is no debounce.

DEFAULT_REPEAT_DELAY

public static final int DEFAULT_REPEAT_DELAY

DEFAULT_REPEAT_RATE

public static final int DEFAULT_REPEAT_RATE

BUTTON_UP

public static final int BUTTON_UP
The button is currently up.

BUTTON_DOWN

public static final int BUTTON_DOWN
The button has just gone down.

BUTTON_AUTO_REPEAT

public static final int BUTTON_AUTO_REPEAT
The button is down and is auto-repeating.

BUTTON_DEBOUNCE

public static final int BUTTON_DEBOUNCE
The button has just gone down and we are waiting for the debounce period.
Constructor Detail

Button

public Button(int portPin,
              boolean upState,
              int repeatDelay,
              int repeatRate)
Create an instance of the Button class with auto-repeat enabled.
Parameters:
portPin - the pin that the button is connected to.
upState - the state of the pin when the button is up.
repeatDelay - the delay in milliseconds after the button has gone down and before it should start repeating.
repeatRate - the time in milliseconds before each repeated button down event.

Button

public Button(int portPin,
              boolean upState)
Create an instance of the Button class without auto-repeat.
Parameters:
portPin - the pin that the button is connected to.
upState - the state of the pin when the button is up.
Method Detail

buttonDown

public boolean buttonDown()
Check whether the button is down. This method should be called continuously. It will monitor the button and the debounce and auto-repeat timers.
Returns:
true if the button is currently down.

getState

public int getState()
Returns the current state of the button.
Returns:
the current button state.