DistanceSensor

The distance sensor is an external device that is connected to the hub through a port. The distance sensor is capable of providing light via the front facing LEDs on the device, and can retrieve the distance in millimeters of a nearby object it is pointed towards.

GetPort()

Returns

integer
Returns the port number of the distance sensor

Parameters

None

Example

1 2 3 4 5 6 use Libraries.Robots.Spike.DistanceSensor use Libraries.Robots.Spike.Port Port port DistanceSensor ds ds:SetPort(port:A) integer distanceSensorPort = ds:GetPort()

SetPort(integer port)

Returns

None

Parameters

  1. 1.integerport

    The port (A through F or 0 through 5) the distance sensor is attached to

Example

1 2 3 4 5 6 use Libraries.Robots.Spike.DistanceSensor use Libraries.Robots.Spike.Port Port port DistanceSensor ds ds:SetPort(port:A) ds:SetPort(0)

GetDistance()

Returns

integer
Returns the distance in millimeters from the distance sensor, returns -1 if the sensor cannot read a valid distance

Parameters

None

Example

1 2 3 4 5 6 use Libraries.Robots.Spike.DistanceSensor use Libraries.Robots.Spike.Port Port port DistanceSensor ds ds:SetPort(port:A) integer currentDistance = ds:GetDistance

GetPixel(integer x, integer y)

Returns

integer
Returns the intensity, a value between 0 and 100, of a specific pixel on the light display on the distance sensor

Parameters

  1. 1.integerx

    The x coordinate from 0 to 1

  2. 2.integery

    The y coordinate from 0 to 1

Example

1 2 3 4 5 6 use Libraries.Robots.Spike.DistanceSensor use Libraries.Robots.Spike.Port Port port DistanceSensor ds ds:SetPort(port:A) integer firstPixel = ds:GetPixel(0, 0)

SetPixel(integer x, integer y, integer intensity)

Returns

None
Sets the intensity of a specific pixel on the light display on the distance sensor

Parameters

  1. 1.integerx

    The x coordinate from 0 to 1

  2. 2.integery

    The y coordinate from 0 to 1

  3. 3.integerintensity

    The intensity of the provided pixel from 0 to 100

Example

1 2 3 4 5 6 use Libraries.Robots.Spike.DistanceSensor use Libraries.Robots.Spike.Port Port port DistanceSensor ds ds:SetPort(port:A) ds:SetPixel(0, 0, 100)

ClearLights()

Returns

None
Shuts off all lights on the light display on the distance sensor

Parameters

None

Example

1 2 3 4 5 6 use Libraries.Robots.Spike.DistanceSensor use Libraries.Robots.Spike.Port Port port DistanceSensor ds ds:SetPort(port:A) ds:ClearLights()

SetAllLights(integer intensity)

Returns

None
Sets all lights on the display to the provided intensity

Parameters

  1. 1.integerintensity

    The intensity of the lights from 0 to 100

Example

1 2 3 4 5 6 use Libraries.Robots.Spike.DistanceSensor use Libraries.Robots.Spike.Port Port port DistanceSensor ds ds:SetPort(port:A) ds:SetAllLights(50)

Show(Array<integer> pixels)

Returns

None
Sets the light intensity of the display pixel by pixel based on the values in a length 4 array of integers from 0 to 100

Parameters

  1. 1.Array<integer>pixels

    An Array<integer> of length 4 containing intensity values for each pixel

Example

1 2 3 4 5 6 7 8 9 10 11 12 use Libraries.Robots.Spike.DistanceSensor use Libraries.Containers.Array use Libraries.Robots.Spike.Port Port port DistanceSensor ds ds:SetPort(port:A) Array<integer> pixels pixels:Add(0) pixels:Add(25) pixels:Add(50) pixels:Add(100) ds:Show(pixels)