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.
integer
None
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()
None
integerport
The 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)
integer
None
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
integer
integerx
The x coordinate from 0 to 1
integery
The 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)
None
integerx
The x coordinate from 0 to 1
integery
The y coordinate from 0 to 1
integerintensity
The 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)
None
None
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()
None
integerintensity
The 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)
None
Array<integer>pixels
An 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)