ColorMatrix

Package: Libraries.Robots.Spike · Inherits from: Libraries.Language.Object

The color matrix is an external device that is connected to the hub through a port. The color matrix is a 3x3 matrix of lights where the color and brightness of each pixel can be changed to display things.

Example Code


use Libraries.Robots.Spike.ColorMatrix
use Libraries.Robots.Spike.Color
use Libraries.Robots.Spike.Port
ColorMatrix cm
Color color
Port port
cm:SetPort(port:A)
cm:SetPixelColor(0, 0, color:RED, 100)

Actions

Clear()

Clears all pixels on the color matrix

Example

use Libraries.Robots.Spike.ColorMatrix
use Libraries.Robots.Spike.Port
ColorMatrix cm
Port port
cm:SetPort(port:A)
cm:Clear()

GetPixelColor(integer x, integer y)

Returns the current color and intensity of the pixel at the provided x and y location

Parameters

  • x integer: The x location of the pixel, 0 to 2
  • y integer: The y location of the pixel, 0 to 2

Returns

Libraries.Containers.Array<integer>: An array of size 2 with the color and intensity of the pixel

Example

use Libraries.Robots.Spike.ColorMatrix
use Libraries.Robots.Spike.Port
use Libraries.Containers.Array
ColorMatrix cm
Port port
cm:SetPort(port:A)
Array<integer> colorIntensity = cm:GetPixelColor(0, 0)

GetPort()

Returns the currently assigned port for this color matrix

Returns

integer: The current port number

Example

use Libraries.Robots.Spike.ColorMatrix
ColorMatrix cm
integer port = cm:GetPort()

SetPixelColor(integer x, integer y, integer color, integer intensity)

Sets the color and intensity of the pixel at the provided x and y location

Parameters

  • x integer: The x location of the pixel, 0 to 2
  • y integer: The y location of the pixel, 0 to 2
  • color integer: The color constant to set the pixel to (see Color)
  • intensity integer: The intensity (brightness) to set the pixel to

Example

use Libraries.Robots.Spike.ColorMatrix
use Libraries.Robots.Spike.Color
use Libraries.Robots.Spike.Port
ColorMatrix cm
Color color
Port port
cm:SetPort(port:A)
cm:SetPixelColor(0, 0, color:RED, 100)

SetPort(integer port)

Sets the port for this color matrix

Parameters

  • port integer: The port to assign

Example

use Libraries.Robots.Spike.ColorMatrix
use Libraries.Robots.Spike.Port
ColorMatrix cm
Port port
cm:SetPort(port:A)

ShowColors(Libraries.Containers.Array<integer> colorValues, Libraries.Containers.Array<integer> intensityValues)

Changes the color and intensity (brightness) of all pixels from the provided color and intensity arrays

Parameters

Example

use Libraries.Robots.Spike.ColorMatrix
use Libraries.Robots.Spike.Color
use Libraries.Robots.Spike.Port
use Libraries.Containers.Array
ColorMatrix cm
Color color
Port port
Array<integer> colors
Array<integer> intensities
repeat 9 times
    colors:Add(color:RED)
    intensities:Add(100)
end
cm:SetPort(port:A)
cm:ShowColors(colors, intensities)

Inherited Actions

3 actions from Libraries.Language.Object