Eye#
Introduction#
The VEX GO Eye Sensor can detect objects and identify their color, brightness, and hue. It also allows you to adjust detection range and lighting settings for more accurate readings.
Below is a list of all available blocks:
set eye light – Turn the Eye’s light on or off.
set eye range – Set the Eye’s detection range.
set eye power – Set the Eye’s light power level.
eye found object? – Checks if the Eye detects an object.
eye detects color? – Checks if the Eye detects a specific color.
eye brightness – Return the brightness detected by the Eye.
eye hue – Return the hue detected by the Eye.
set eye light#
The set eye light block turns the Eye Sensor’s light on or off.
set eye light [on v]
Parameters |
Description |
|---|---|
state |
The state of the sensor’s light:
|
Example
when started :: hat events
[Build Used: Code Base 2.0 - Eye Forward]
[Turn the light on and off.]
forever
set eye light [on v]
wait [2] seconds
set eye light [off v]
wait [2] seconds
set eye range#
The set eye range block sets the detection range on the Eye Sensor. The default range is far.
set eye to [near v] range
Parameters |
Description |
|---|---|
range |
The sensor’s detection range:
|
Example
when started :: hat events
[Build Used: Code Base 2.0 - Eye Forward]
[Drive to an object with different ranges.]
set eye to [far v] range
drive [forward v]
wait until <eye found an object?>
drive [reverse v] for [100] [mm v] ▶
wait [1] seconds
[Closer detection range.]
set eye to [near v] range
drive [forward v]
wait until <eye found an object?>
stop driving
set eye power#
The set eye power block sets the brightness of the Eye Sensor’s light. If the light is off, this block will turn it on if the new brightness is not 0%.
set eye light power to [50]%
Parameters |
Description |
|---|---|
brightness |
The new brightness to set the sensor’s light to from 0% to 100%. |
Example
when started :: hat events
[Build Used: Code Base 2.0 - Eye Forward]
[Turn on the light at different brightnesses.]
set eye light power to [25]%
wait [2] seconds
set eye light power to [50]%
wait [2] seconds
set eye light power to [100]%
eye found object?#
The eye found object? block returns a Boolean indicating whether or not the Eye Sensor detects an object within range.
True – The sensor has detected an object.
False – The sensor has not detected an object.
<eye found an object?>
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started :: hat events
[Build Used: Code Base 2.0 - Eye Forward]
[Drive forward until an object is detected.]
drive [forward v]
wait until <eye found an object?>
stop driving
eye detects color?#
The eye detects color? block returns a Boolean indicating whether the Eye Sensor detects a specified color.
True – The sensor detects the specified color.
False – The sensor does not detect the specified color.
<eye detects [red v]?>
Parameters |
Description |
|---|---|
color |
The color to detect:
|
Example
when started :: hat events
[Build Used: Super Code Base 2.0]
[Drive forward until a Green Disk is detected.]
drive [forward v]
wait [0.2] seconds
wait until <eye detects [green v]?>
stop driving
eye brightness#
The eye brightness block returns the brightness detected by the Eye Sensor from 0% to 100%.
(eye brightness in %)
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started :: hat events
[Build Used: Super Code Base 2.0]
[Monitor the brightness until a Red Disk is detected.]
drive [forward v]
repeat until <eye detects [red v]?>
clear all rows
print (eye brightness in %) ▶
wait [0.1] seconds
end
stop driving
eye hue#
The eye hue block returns the hue detected by the Eye Sensor in degrees from 0 to 359.
(eye hue in degrees)
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started :: hat events
[Build Used: Code Base 2.0 - Eye Forward]
[Display the hue of a pink GO piece.]
forever
clear all rows
if <[10] [math_less_than v] (eye hue in degrees) [math_less_than v] [40]> then
print [Pink!] ▶
else
print [Not pink.] ▶