Color Sensor#
Introduction#
The Color Sensor category includes blocks that report color-based information from a VEX IQ (2nd generation) Color Sensor. These blocks allow your robot to detect when an object is present, recognize specific colors, and return visual data such as brightness and hue.
You can also use blocks to configure the brightness of the sensor’s internal light. These tools are ideal for programs that need to react to colored objects, lighting conditions, or sensor feedback in real time.
Below is a list of available blocks:
Looks – Adjust light settings.
set Color light – Sets the brightness of the Color Sensor’s light.
Sensing – Identify presence and color, and read color characteristics.
Color found an object? – Returns whether any object is detected.
Color detects color? – Returns whether a specific color is detected.
Color color name – Returns the name of the detected color.
Color brightness – Returns detected brightness as a percentage.
Color hue – Returns the hue angle of the detected color.
Looks#
set Color light#
The set Color light block sets the brightness of the Color Sensor’s light.
set [Color1 v] light to (50) %
Parameters |
Description |
---|---|
color sensor |
Which Color Sensor’s light brightness to set, configured in the Devices window. |
brightness |
The brightness of the light from 0 to 100 as a percent. |
Example
when started :: hat events
set [Color12 v] light to (25) %
wait (2) seconds
set [Color12 v] light to (100) %
Sensing#
Color found an object?#
The Color found an object block returns a Boolean indicating whether the Color Sensor has detected any object.
True – The Color Sensor has detected an object.
False – The Color Sensor has not detected an object.
<[Color1 v] found an object?>
Parameters |
Description |
---|---|
color sensor |
Which Color Sensor to use, configured in the Devices window. |
Example
when started :: hat events
[Don't print the message until the Color Sensor detects an object.]
wait until <[Color12 v] found an object?>
print [Color Sensor detected an object] on [Brain v] ◀ and set cursor to next row
Color detects color?#
The Color detects color block returns a Boolean indicating whether the Color Sensor has detected a specific color.
True – The Color Sensor has detected the specified color.
False – The Color Sensor has not detected the specified color.
<[Color1 v] detects [red v]?>
Parameters |
Description |
---|---|
color sensor |
Which Color Sensor to use, configured in the Devices window. |
color |
Which color to check for:
|
Example
when started :: hat events
[Don't print the message until the Color Sensor detects an the color green.]
wait until <[Color12 v] detects [green v]?>
print ([Color12 v] color name) on [Brain v] ◀ and set cursor to next row
Color color name#
The Color color name block returns the name of the color detected by the Color Sensor.
Possible colors are:
red
green
blue
white
yellow
orange
purple
red violet
violet
blue violet
blue green
yellow green
yellow orange
red orange
([Color1 v] color name)
Parameters |
Description |
---|---|
color sensor |
Which Color Sensor to use, configured in the Devices window. |
Example
when started :: hat events
[Don't print the message until the Color Sensor detects an the color green.]
wait until <[Color12 v] detects [green v]?>
print ([Color12 v] color name) on [Brain v] ◀ and set cursor to next row
Color brightness#
The Color brightness block returns the amount of light detected by the Color Sensor in a range from 0% to 100%.
([Color1 v] brightness in %)
Parameters |
Description |
---|---|
color sensor |
Which Color Sensor to use, configured in the Devices window. |
Example
when started :: hat events
print ([Color12 v] brightness in %) on [Brain v] ◀ and set cursor to next row
Color hue#
The Color hue block returns the hue value of the color detected by the Color Sensor.
Hue values range from 0 to 359 degrees, corresponding to positions on the color wheel shown below.
([Color1 v] hue in degrees)
Parameters |
Description |
---|---|
color sensor |
Which Color Sensor to use, configured in the Devices window. |
Example
when started :: hat events
print ([Color12 v] hue in degrees) on [Brain v] ◀ and set cursor to next row