ColorSensor

The color sensor is an external device that is connected to the hub through a port. The color sensor is a unidirectional sensor that measures the intensity and rgb value of reflected light.

GetPort()

Returns

integer
Returns the currently assigned port for this color sensor

Parameters

None

Example

1 2 3 use Libraries.Robots.Spike.ColorSensor ColorSensor cs integer port = cs:GetPort()

SetPort(integer port)

Returns

None

Parameters

  1. 1.integerport

    The port that this color sensor object will be set to

Example

1 2 3 4 5 use Libraries.Robots.Spike.ColorSensor use Libraries.Robots.Spike.Port ColorSensor cs Port port cs:SetPort(port:A)

GetColorInteger()

Returns

integer
Returns the color, which is an integer corresponding to a color from the Color module

Parameters

None

Example

1 2 3 4 5 6 7 8 9 10 11 12 use Libraries.Robots.Spike.ColorSensor use Libraries.Robots.Spike.Color use Libraries.Robots.Spike.Port use Libraries.Robots.Spike.LightMatrix ColorSensor cs Color color LighMatrix lights Port port cs:SetPort(port:A) if cs:GetColorInteger = color:RED lights:Write("Red Detected!") end

GetReflection()

Returns

integer
Returns the intensity of reflected light detected by the color sensor from 0 to 100

Parameters

None

Example

1 2 3 4 5 6 use Libraries.Robots.Spike.ColorSensor use Libraries.Robots.Spike.Port ColorSensor cs Port port cs:SetPort(port:A) integer intensity = cs:GetReflection()

GetRGBI()

Returns

Array<integer>
Returns an Array of integers of length 4, red (from 0 to 255) is at index 0, blue (from 0 to 255) is at index 1, green (from 0 to 255) is at index 2, and the intensity (from 0 to 100) is at index 3

Parameters

None

Example

1 2 3 4 5 6 7 8 use Libraries.Robots.Spike.ColorSensor use Libraries.Robots.Spike.Port use Libraries.Containers.Array ColorSensor cs Port port Array<integer> rgbi cs:SetPort(port:A) rgbi = cs:GetRGBI()