Show:
Extends webduino.Module

The Button Class.

Constructor

webduino.module.Button
(
  • board
  • pin
  • buttonMode
  • sustainedPressInterval
)

Parameters:

  • board webduino.Board

    The board the button is attached to.

  • pin webduino.pin

    The pin the button is connected to.

  • [buttonMode] Number optional

    Type of resistor the button is connected to, either Button.PULL_DOWN or Button.PULL_UP.

  • [sustainedPressInterval] Number optional

    A period of time when the button is pressed and hold for that long, it would be considered a "sustained press." Measured in ms.

Methods

addListener
(
  • type
  • listener
)

Add a listener for a certain type of event.

Parameters:

  • type String

    Event type.

  • listener Function

    Event listener.

emit
(
  • type
  • object,...
)

Emit an event of certain type.

Parameters:

  • type String

    Event type.

  • [object,...] Object optional

    Event object(s).

listeners
(
  • type
)

Return the listener list bound to certain type of event.

Parameters:

  • type String

    Evnet type.

on
(
  • type
  • listener
)

Alias for EventEmitter.addListener(type, listener)

Parameters:

  • type String

    Event type.

  • listener Function

    Event listener.

once
(
  • type
  • listener
)

Add a one-time listener for a certain type of event.

Parameters:

  • type String

    Event type.

  • listener Function

    Event listener.

removeAllListeners
(
  • type
)

Remove all listeners of certain type.

Parameters:

  • type String

    Event type.

removeListener
(
  • type
  • listener
)

Remove a listener for certain type of event.

Parameters:

  • type String

    Event type.

  • listener Function

    Event listener.

setMaxListeners
(
  • n
)

Set maximum number of listeners that is allow to bind on an emitter.

Parameters:

  • n Number

    Number of listeners.

Properties

INTERNAL_PULL_UP

Number const static

Indicates the internal-pull-up resistor type.

PULL_DOWN

Number const static

Indicates the pull-down resistor type.

PULL_UP

Number const static

Indicates the pull-up resistor type.

Attributes

buttonMode

Number buttonMode readonly

Return the button mode.

sustainedPressInterval

Number

Return the sustained-press interval.

type

String readonly

Type of the module.

Events

ButtonEvent.LONG_PRESS

Fires when a button is long-pressed.

ButtonEvent.PRESS

Fires when a button is pressed.

ButtonEvent.RELEASE

Fires when a button is released.

ButtonEvent.SUSTAINED_PRESS

Fires when a button is sustained-pressed.