Class BO.io.Button
Extends
BO.PhysicalInputBase.
Creates and interface to a physical button. The Button object
dispatches events on state changes such as Pressed, Released and
Sustained Press. The Button object also handles debouncing.
Defined in: Button.js.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
BO.io.Button(board, pin, buttonMode, sustainedPressInterval)
An object to represent a physical button.
|
| Field Attributes | Field Name and Description |
|---|---|
|
The debounce time interval in milliseconds.
|
|
| <static> |
BO.io.Button.INTERNAL_PULL_UP
|
|
[read-only] The pin number of the pin the button is attached to.
|
|
| <static> <constant> |
BO.io.Button.PULL_DOWN
|
| <static> <constant> |
BO.io.Button.PULL_UP
|
|
The delay time (in milliseconds) the button must be held before a
sustained press event is fired.
|
- Methods borrowed from class BO.PhysicalInputBase:
- addEventListener, dispatchEvent, hasEventListener, removeEventListener
| Event Attributes | Event Name and Description |
|---|---|
|
The longPress event is dispatched once when the button has been held for
the time duration specified by the sustainedPressInterval property.
|
|
|
The pressed event is dispatched when the button is pressed.
|
|
|
The released event is dispatched when the button is released.
|
|
|
The sustainedPress event is dispatched continuously at the rate
specified by the sustainedPressInterval property while the button is
held.
|
Class Detail
BO.io.Button(board, pin, buttonMode, sustainedPressInterval)
An object to represent a physical button. The advantage of using the
Button class over listening for pin change events on a Pin object, is
that the Button class handles debouncing and provides helpful button
events: Pressed, Released, Long Press and Sustained Press
PULL_UP vs PULL_DOWN. If the other end of the resistor connected to the button is connected to ground, configuration is PULL_DOWN, if the resistor is connected to power, then the configuration is PULL_UP.
- Parameters:
- {IOBoard} board
- A reference to the IOBoard instance
- {Pin} pin
- A reference to the Pin the button is connected to.
- {Number} buttonMode
- The mode of the button (either Button.PULL_DOWN or Button.PULL_UP if wired with external resistors or Button.INTERNAL_PULL_UP if using the internal pull-up resistors. Default is PULL_DOWN.
- {Number} sustainedPressInterval
- The delay time in milliseconds before a sustained press event is fired.
Field Detail
{Number}
debounceInterval
The debounce time interval in milliseconds.
<static>
BO.io.Button.INTERNAL_PULL_UP
{Number}
pinNumber
[read-only] The pin number of the pin the button is attached to.
<static> <constant>
BO.io.Button.PULL_DOWN
<static> <constant>
BO.io.Button.PULL_UP
{Number}
sustainedPressInterval
The delay time (in milliseconds) the button must be held before a
sustained press event is fired.
Event Detail
{BO.io.ButtonEvent.LONG_PRESS}
longPress
The longPress event is dispatched once when the button has been held for
the time duration specified by the sustainedPressInterval property.
- This event has the following properties:
- {BO.io.Button} target
- A reference to the Button object
{BO.io.ButtonEvent.PRESS}
pressed
The pressed event is dispatched when the button is pressed.
- This event has the following properties:
- {BO.io.Button} target
- A reference to the Button object
{BO.io.ButtonEvent.RELEASE}
released
The released event is dispatched when the button is released.
- This event has the following properties:
- {BO.io.Button} target
- A reference to the Button object
{BO.io.ButtonEvent.SUSTAINED_PRESS}
sustainedPress
The sustainedPress event is dispatched continuously at the rate
specified by the sustainedPressInterval property while the button is
held.
- This event has the following properties:
- {BO.io.Button} target
- A reference to the Button object
