Show:
Extends webduino.Module

The Ultrasonic class.

Constructor

webduino.module.Ultrasonic
(
  • board
  • trigger
  • echo
)

Parameters:

  • board webduino.Board

    The board the ultrasonic sensor is attached to.

  • trigger webduino.Pin

    The trigger pin the sensor is connected to.

  • echo webduino.Pin

    The echo pin the sensor is connected to.

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.

ping
(
  • callback
  • interval
)
Promise

Transmit an ultrasonic to sense the distance at a (optional) given interval.

Parameters:

  • [callback] Function optional

    Callback when a response is returned.

  • [interval] Number optional

    Interval between each transmission. If omitted the ultrasonic will be transmitted once.

Returns:

Promise:

A promise when the ping response is returned. Will not return anything if a callback function is given.

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.

stopPing ()

Stop transmitting any ultrasonic.

Attributes

distance

Number readonly

Distance returned from the previous transmission.

type

String readonly

Type of the module.

Events

UltrasonicEvent.PING

Fires when receiving a ping response.

UltrasonicEvent.PING_ERROR

Fires when receiving a ping-error response.