Sphero Movement Panel icon Sphero Movement Panel — Control Sphero via Bluetooth in ARC. Detects two COM ports (one connects); requires deleting and re-pairing after disconnects or reboots. Try it →
 

Ping

Read HC-SR04 style ultrasonic distance sensors connected to an EZB. Each sensor uses two ports, trigger and echo. Distances are a number from 0 to 255, larger meaning farther. The wait commands pause the script until something comes closer or moves away.

Where to find it: type Ping. in a JavaScript script, or open the ARCx API view of the script editor and expand Ping


Commands

Command What it does
Ping.get Reads the distance from an HC-SR04 ultrasonic ping sensor on the first EZB, as a value from 0 to 255 (larger is farther).
Ping.waitForBetween Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads a distance from low to high, inclusive, checking about every 100 ms.
Ping.waitForEquals Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads exactly the given distance, checking about every 100 ms.
Ping.waitForHigher Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads a distance above the given one, checking about every 100 ms.
Ping.waitForLower Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads a distance below the given one, checking about every 100 ms.

Details

Ping.get

Reads the distance from an HC-SR04 ultrasonic ping sensor on the first EZB, as a value from 0 to 255 (larger is farther). Readings are cached for 200 ms. Raises an error if the EZB is not connected or its firmware does not support ping sensors.

Ping.get(triggerPort, echoPort)
Ping.get(triggerPort, echoPort, ezbIndex)
Value Type What it is
triggerPort number The digital port the sensor's trigger pin is wired to, such as d0.
echoPort number The digital port the sensor's echo pin is wired to, such as d1.
ezbIndex number Optional. Which EZB to use, 0 being the first one.

Gives back: number. The distance value, 0 to 255.

Ping.waitForBetween

Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads a distance from low to high, inclusive, checking about every 100 ms. Raises an error if the EZB is not connected or its firmware does not support ping sensors.

Ping.waitForBetween(triggerPort, echoPort, low, high)
Ping.waitForBetween(triggerPort, echoPort, low, high, ezbIndex)
Value Type What it is
triggerPort number The digital port the sensor's trigger pin is wired to, such as d0.
echoPort number The digital port the sensor's echo pin is wired to, such as d1.
low number The smallest distance to accept, 0 to 255.
high number The largest distance to accept, 0 to 255.
ezbIndex number Optional. Which EZB to use, 0 being the first one.

Gives back: number. The distance that was read, 0 to 255, or -1 if the script was stopped first.

Ping.waitForEquals

Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads exactly the given distance, checking about every 100 ms. Raises an error if the EZB is not connected or its firmware does not support ping sensors.

Ping.waitForEquals(triggerPort, echoPort, distance)
Ping.waitForEquals(triggerPort, echoPort, distance, ezbIndex)
Value Type What it is
triggerPort number The digital port the sensor's trigger pin is wired to, such as d0.
echoPort number The digital port the sensor's echo pin is wired to, such as d1.
distance number The distance to wait for, 0 to 255.
ezbIndex number Optional. Which EZB to use, 0 being the first one.

Gives back: number. The distance that was read, 0 to 255, or -1 if the script was stopped first.

Ping.waitForHigher

Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads a distance above the given one, checking about every 100 ms. Raises an error if the EZB is not connected or its firmware does not support ping sensors.

Ping.waitForHigher(triggerPort, echoPort, distance)
Ping.waitForHigher(triggerPort, echoPort, distance, ezbIndex)
Value Type What it is
triggerPort number The digital port the sensor's trigger pin is wired to, such as d0.
echoPort number The digital port the sensor's echo pin is wired to, such as d1.
distance number Wait for a reading above this distance, 0 to 255.
ezbIndex number Optional. Which EZB to use, 0 being the first one.

Gives back: number. The distance that was read, 0 to 255, or -1 if the script was stopped first.

Ping.waitForLower

Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads a distance below the given one, checking about every 100 ms. Raises an error if the EZB is not connected or its firmware does not support ping sensors.

Ping.waitForLower(triggerPort, echoPort, distance)
Ping.waitForLower(triggerPort, echoPort, distance, ezbIndex)
Value Type What it is
triggerPort number The digital port the sensor's trigger pin is wired to, such as d0.
echoPort number The digital port the sensor's echo pin is wired to, such as d1.
distance number Wait for a reading below this distance, 0 to 255.
ezbIndex number Optional. Which EZB to use, 0 being the first one.

Gives back: number. The distance that was read, 0 to 255, or -1 if the script was stopped first.