BO.io.Button Class
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.
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
.
Constructor
BO.io.Button
-
board
-
pin
-
buttonMode
-
sustainedPressInterval
Parameters:
-
board
IOBoardA reference to the IOBoard instance
-
pin
PinA reference to the Pin the button is connected to.
-
buttonMode
NumberThe mode of the button (either
Button.PULL_DOWN
orButton.PULL_UP
if wired with external resistors orButton.INTERNAL_PULL_UP
if using the internal pull-up resistors. Default isPULL_DOWN
. -
sustainedPressInterval
NumberThe delay time in milliseconds before a sustained press event is fired.
Item Index
Methods
Properties
- Button.INTERNAL_PULL_UP static
- Button.PULL_DOWN static
- Button.PULL_UP static
- debounceInterval
- pinNumber
- sustainedPressInterval
Events
Methods
addEventListener
-
type
-
listener
Parameters:
-
type
StringThe event type
-
listener
FunctionThe function to be called when the event is fired
dispatchEvent
-
type
-
optionalParams
Parameters:
-
type
EventThe Event object.
-
optionalParams
ObjectOptional parameters passed as an object. return {boolean} True if dispatch is successful, false if not.
hasEventListener
-
type
Parameters:
-
type
StringThe event type return {boolean} True is listener exists for this type, false if not.
onPinChange
()
private
pressed
()
private
released
()
private
removeEventListener
-
type
-
listener
Parameters:
-
type
StringThe event type
-
listener
FunctionThe function to be called when the event is fired
sustainedPress
()
private
Properties
Button.INTERNAL_PULL_UP
Unknown
static
Button.PULL_DOWN
Unknown
static
Button.PULL_UP
Unknown
static
debounceInterval
Number
The debounce time interval in milliseconds.
pinNumber
Number
[read-only] The pin number of the pin the button is attached to.
sustainedPressInterval
Number
The delay time (in milliseconds) the button must be held before a sustained press event is fired.
Events
longPress
BO.io.ButtonEvent.LONG_PRESS
The longPress event is dispatched once when the button has been held for the time duration specified by the sustainedPressInterval property.
Event Payload:
-
target
BO.io.ButtonA reference to the Button object
pressed
BO.io.ButtonEvent.PRESS
The pressed event is dispatched when the button is pressed.
Event Payload:
-
target
BO.io.ButtonA reference to the Button object
released
BO.io.ButtonEvent.RELEASE
The released event is dispatched when the button is released.
Event Payload:
-
target
BO.io.ButtonA reference to the Button object
sustainedPress
BO.io.ButtonEvent.SUSTAINED_PRESS
The sustainedPress event is dispatched continuously at the rate specified by the sustainedPressInterval property while the button is held.
Event Payload:
-
target
BO.io.ButtonA reference to the Button object