光学传感器#
介绍#
The Optical Sensing category includes blocks that control and retrieve data from the VEX IQ (2nd gen) Optical Sensor. This sensor can detect objects, identify colors, and measure brightness and hue.
Below is a list of all blocks:
set Optical light — Turns the Optical Sensor light on or off.
set Optical light power — Sets the brightness of the Optical Sensor’s light.
Optical found object? — Returns whether an object is detected.
Optical detects color? — Returns whether a specific color is detected.
Optical color name — Returns the name of the color detected.
Optical brightness — Returns the brightness detected by the sensor.
Optical hue — Returns the hue value of the detected color.
When Optical — Executes the attached stack of blocks when the Optical Sensor detects or loses an object.
设置光学灯#
设置光学光源 模块用于打开或关闭光学传感器上的光源。当光学传感器在黑暗环境中观察物体时,光源可以帮助它更好地识别物体。
设定 [Optical 1 v] 灯 [on v]
参数 |
描述 |
|---|---|
光学传感器 |
使用哪种光学传感器,在设备窗口中配置。 |
状态 |
要设置的光学传感器灯的状态:
|
例子
当开始
[Repeatedly flash the Optical Sensor's lights.]
永久循环
设定 [Optical 1 v] 灯 [on v]
等待 (1) 秒
设定 [Optical 1 v] 灯 [灭 v]
等待 (1) 秒
设置光学光功率#
The set Optical light power block sets the brightness of the Optical Sensor’s light, helping create a more consistent and reliable light source for the sensor.
set [Optical1 v] light power to (50)%
**注意:**如果光学传感器的灯关闭,此块将打开灯。
参数 |
描述 |
|---|---|
光学传感器 |
使用哪种光学传感器,在设备窗口中配置。 |
亮度 |
光学传感器的光亮度从 0 到 100 的百分比。 |
例子
当开始
[Repeatedly change the brightness of the Optical Sensor's lights.]
永久循环
set [Optical1 v] light power to (10)%
等待 (2) 秒
set [Optical1 v] light power to (50)%
等待 (2) 秒
set [Optical1 v] light power to (100)%
等待 (2) 秒
光学发现物体?#
**光学发现物体?**块返回一个布尔值,指示光学传感器是否检测到物体。
True — The Optical Sensor has detected an object.
False — The Optical Sensor has not detected an object.
<[Optical 1 v] 发现对象?>
参数 |
描述 |
|---|---|
光学传感器 |
使用哪种光学传感器,在设备窗口中配置。 |
例子
当开始
[Turn until the Optical Sensor detects an object.]
设定转向速度为 (10) [% v]
set [Optical1 v] light power to [75]%
[右 v] 转
等到 <[Optical 1 v] 发现对象?>
在屏幕上打印 [Object detected]◀ 并设定光标为下一行
驱动停止
光学检测颜色?#
**光学检测颜色?**块返回一个布尔值,指示光学传感器是否检测到特定颜色。
True — The Optical Sensor has detected the specified color.
False — The Optical Sensor has not detected the specified color.
<[Optical 1 v] 测得 [红色 v]?>
参数 |
描述 |
|---|---|
光学传感器 |
使用哪种光学传感器,在设备窗口中配置。 |
颜色 |
要检查哪种颜色:
|
例子
当开始
[Turn until the Optical Sensor detects a red object.]
设定转向速度为 (10) [% v]
set [Optical1 v] light power to [75]%
[右 v] 转
等到 <[Optical 1 v] 测得 [红色 v]?>
在屏幕上打印 [Red detected]◀ 并设定光标为下一行
驱动停止
光学颜色名称#
光学颜色名称块返回光学传感器检测到的颜色的名称。
可能的颜色有:
红色的
绿色的
蓝色的
黄色的
橙子
紫色的
青色
Note: This block can be inserted into the set Touch LED color block to make the Touch LED match the detected color.
([Optical 1 v] 颜色)
参数 |
描述 |
|---|---|
光学传感器 |
使用哪种光学传感器,在设备窗口中配置。 |
例子
当开始
[Display a message when the Optical Sensor detects red.]
等到 <[Optical 1 v] 测得 [红色 v]?>
在屏幕上打印 ([Optical 1 v] 颜色)◀ 并设定光标为下一行
光学亮度#
光学亮度块返回光学传感器检测到的光量,范围从 0% 到 100%。
([Optical 1 v] 亮度百分比)
参数 |
描述 |
|---|---|
光学传感器 |
使用哪种光学传感器,在设备窗口中配置。 |
例子
当开始
[Display the brightness when the Optical Sensor detects red.]
等到 <[Optical 1 v] 测得 [红色 v]?>
在屏幕上打印 ([Optical 1 v] 亮度百分比)◀ 并设定光标为下一行
光学色调#
光学色调块返回光学传感器检测到的颜色的色调值。
色调值范围从 0 到 359 度,对应于下面显示的色轮上的位置。

([Optical 1 v] 色调度数)
参数 |
描述 |
|---|---|
光学传感器 |
使用哪种光学传感器,在设备窗口中配置。 |
例子
当开始
[Print when the Optical Sensor detects pink.]
永久循环
清屏
在屏幕上设定光标至 (1) 行 (1) 列
如果 <<([Optical 1 v] 色调度数) [math_greater_than v] [290]> 与 <([Optical 1 v] 色调度数) [math_less_than v] [350]>> 那么
在屏幕上打印 [Pink!]▶
等待 (0.1) 秒
否则
在屏幕上打印 [Not pink.]▶
等待 (0.1) 秒
当光学#
当选定的光学传感器检测到或丢失物体时,当光学块会运行附加的块堆栈。
当 [Optical 1 v] [detects v] 一个对象
参数 |
描述 |
|---|---|
光学传感器 |
使用哪种光学传感器,在设备窗口中配置。 |
状态 |
哪些动作触发帽子积木:
|
例子
当 [Optical 1 v] [detects v] 一个对象
[Find an object when it is lost.]
[右 v] 转
等到 <[Optical 1 v] 发现对象?>
驱动停止