Libraries.Robots.Spike.ColorSensor Documentation

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.

Example Code

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

Inherits from: Libraries.Language.Object

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetColorInteger()

Returns the detected color as an integer corresponding to a color from the Color module

Return

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

Example

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

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetPort()

Returns the currently assigned port for this color sensor

Return

integer: The current port number

Example

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

GetRGBI()

Returns the red, green, blue, and intensity values of the reflected light detected by the color sensor in an array of 4 integers.

Return

Libraries.Containers.Array: An Array of length 4, red (from 0 to 1024) is at index 0, blue (from 0 to 1024) is at index 1, green (from 0 to 1024) is at index 2, and the intensity (from 0 to 1024) is at index 3

Example

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()

GetReflection()

Returns the intensity of the reflected light detected by the sensor

Return

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

Example

use Libraries.Robots.Spike.ColorSensor
use Libraries.Robots.Spike.Port
ColorSensor cs
Port port
cs:SetPort(port:A)
integer intensity = cs:GetReflection()

SetPort(integer port)

Sets the port for this color sensor

Parameters

  • integer port: The port to assign

Example

use Libraries.Robots.Spike.ColorSensor
use Libraries.Robots.Spike.Port
ColorSensor cs
Port port
cs:SetPort(port:A)