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.
integerNone1
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()NoneintegerportThe port (A through F or 0 through 5) the distance sensor is attached to
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)integerNone1
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:GetDistanceintegerintegerxThe x coordinate from 0 to 1
integeryThe y coordinate from 0 to 1
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)NoneintegerxThe x coordinate from 0 to 1
integeryThe y coordinate from 0 to 1
integerintensityThe intensity of the provided pixel from 0 to 100
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)NoneNone1
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()NoneintegerintensityThe intensity of the lights from 0 to 100
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)NoneArray<integer>pixelsAn Array<integer> of length 4 containing intensity values for each pixel
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)