颜色传感器#
介绍#
The Color Sensor category includes blocks that report color-based information from a VEX IQ (2nd gen) 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.
您还可以使用模块来配置传感器内部灯光的亮度。这些工具非常适合需要实时响应彩色物体、光照条件或传感器反馈的程序。
Below is a list of all 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.
外观#
设置颜色灯#
设置颜色灯块设置颜色传感器灯的亮度。
设定 [Color 1 v] 灯亮为 (50)%
参数 |
描述 |
|---|---|
颜色传感器 |
设置哪个颜色传感器的灯光亮度,在设备窗口中配置。 |
亮度 |
光的亮度从 0 到 100 的百分比。 |
例子
当开始
[Light up the Color Sensor dimmer.]
设定 [Color 1 v] 灯亮为 (25)%
等待 (2) 秒
[Light up the Color Sensor brighter.]
设定 [Color 1 v] 灯亮为 (100)%
传感#
颜色找到了一个物体?#
颜色发现物体块返回一个布尔值,指示颜色传感器是否检测到任何物体。
True — The Color Sensor has detected an object.
False — The Color Sensor has not detected an object.
<[Color 1 v] 发现对象?>
参数 |
描述 |
|---|---|
颜色传感器 |
使用哪种颜色传感器,在设备窗口中配置。 |
例子
当开始
[Print a different message when an object is in front of the Color Sensor.]
永久循环
在 [Brain v] 设定光标至 (1) 行 (1) 列
如果 <[Color 1 v] 发现对象?> 那么
在 [Brain v] ▶上打印 [Object detected]
否则
在 [Brain v] ▶上打印 [Nothing detected]
结束
清除 [Brain v] 第 (1) 行
颜色检测颜色?#
颜色检测颜色块返回一个布尔值,指示颜色传感器是否检测到特定的颜色。
True — The Color Sensor has detected the specified color.
False — The Color Sensor has not detected the specified color.
<[Color 1 v] 测得 [红色 v]?>
参数 |
描述 |
|---|---|
颜色传感器 |
使用哪种颜色传感器,在设备窗口中配置。 |
颜色 |
要检查哪种颜色:
|
例子
当开始
[Turn until the Color Sensor detects green.]
[右 v] 转
等到 <[Color 1 v] 测得 [绿色 v]?>
驱动停止
颜色颜色名称#
颜色颜色名称块返回颜色传感器检测到的颜色的名称。
可能的颜色有:
红色的
绿色的
蓝色的
白色的
黄色的
橙子
紫色的
红紫色
紫色
蓝紫色
蓝绿色
黄绿色
黄橙色
红橙色
Note: This block can be inserted into the set Touch LED color block to make the Touch LED match the detected color.
([Color 1 v] 颜色)
参数 |
描述 |
|---|---|
颜色传感器 |
使用哪种颜色传感器,在设备窗口中配置。 |
例子
当开始
[Stop and print when the Color Sensor detects green.]
[右 v] 转
等到 <[Color 1 v] 测得 [绿色 v]?>
驱动停止
在 [Brain v] 上打印 ([Color 1 v] 颜色) ◀ 并设定光标为下一行
颜色亮度#
颜色亮度块返回颜色传感器检测到的光量,范围从 0% 到 100%。
([Color 1 v] 亮度百分比)
参数 |
描述 |
|---|---|
颜色传感器 |
使用哪种颜色传感器,在设备窗口中配置。 |
例子
当开始
[Stop and print the brightness when the Color Sensor detects green.]
[右 v] 转
等到 <[Color 1 v] 测得 [绿色 v]?>
驱动停止
在 [Brain v] 上打印 ([Color 1 v] 亮度百分比) ◀ 并设定光标为下一行
色调#
色调块返回颜色传感器检测到的颜色的色调值。
色调值范围从 0 到 359 度,对应于下面显示的色轮上的位置。

([Color 1 v] 色调度数)
参数 |
描述 |
|---|---|
颜色传感器 |
使用哪种颜色传感器,在设备窗口中配置。 |
例子
当开始
[Print when the Color Sensor detects pink.]
永久循环
清除 [Brain v] 所有行
在 [Brain v] 设定光标至 (1) 行 (1) 列
如果 <<([Color 1 v] 色调度数) [math_greater_than v] [290]> 与 <([Color 1 v] 色调度数) [math_less_than v] [350]>> 那么
在 [Brain v] ▶上打印 [Pink!]
等待 (0.1) 秒
否则
在 [Brain v] ▶上打印 [Not pink.]
等待 (0.1) 秒