Service_SPIKE.DistanceSensor

DistanceSensor

Example

// Initialize the DistanceSensor
var distance_sensor = new serviceSPIKE.DistanceSensor("A");

Methods

inner get_distance_cm() → {number}

Retrieves the measured distance in centimeters.

Returns:
number -

[0 to 200]

To Do:
  • find the short_range handling ujsonrpc script
Example
var distance_cm = distance_sensor.get_distance_cm();

inner get_distance_inches() → {number}

Retrieves the measured distance in inches.

Returns:
number -

[0 to 79]

To Do:
  • find the short_range handling ujsonrpc script
Example
var distance_inches = distance_sensor.get_distance_inches();

inner get_distance_percentage() → {number/string}

Retrieves the measured distance in percent.

Returns:
number/string -

[0 to 100] or 'none' if no distance is read var distance_percentage = distance_sensor.get_distance_percentage();

inner wait_for_distance_farther_than(threshold, unit, callback)

Waits until the measured distance is greater than distance.

Parameters:
Name Type Description
threshold integer
unit string

'cm','in','%'

callback function

function to execute when distance is farther than threshold

Example
distance_sensor.wait_for_distance_farther_than(10, 'cm', function () {
     console.log("distance is farther than 10 CM");
})

inner wait_for_distance_closer_than(threshold, unit, callback)

Waits until the measured distance is less than distance.

Parameters:
Name Type Description
threshold integer
unit string

'cm','in','%'

callback function

function to execute when distance is closer than threshold

Example
distance_sensor.wait_for_distance_closer_than(10, 'cm', function () {
     console.log("distance is closer than 10 CM");
})   

inner light_up(right_top, left_top, right_bottom, left_bottom)

Sets the brightness of the individual lights on the Distance Sensor.

Parameters:
Name Type Description
right_top integer

Brightness [1-100]

left_top integer

Brightness [1-100]

right_bottom integer

Brightness [1-100]

left_bottom integer

Brightness [1-100]

Example
distance_sensor.light_up(100,100,100,100);

inner light_up_all(brightnessopt)

Lights up all of the lights on the Distance Sensor at the specified brightness.

Parameters:
Name Type Attributes Default Description
brightness number <optional>
100

The specified brightness of all of the lights

Example
distance_sensor.light_up_all(50)