颜色传感器#

介绍#

颜色传感器类别包含一些模块,用于报告来自 VEX IQ 颜色传感器的颜色信息。这些模块可以让你的机器人检测物体是否存在、识别特定颜色,并返回亮度、色调等视觉数据。

您还可以使用模块来配置传感器内部灯光的亮度。这些工具非常适合需要实时响应彩色物体、光照条件或传感器反馈的程序。

以下是所有模块的列表:

设置颜色灯#

The set Color light stack block sets how bright the Color Sensor’s light is. The light can help the Color Sensor detect objects and colors more clearly.

A higher percentage makes the light brighter. A lower percentage makes the light dimmer.

If the Color Sensor’s light is off, setting the light power above 0% will turn the light on.

If the Color Sensor’s light is on, setting the light power at 0% will turn the light off.

设定 [Color 1 v] 灯亮为 (50)%

参数

描述

颜色传感器

设置哪个颜色传感器的灯光亮度,在设备窗口中配置。

亮度

The brightness of the Color Sensor’s light from 0% to 100% as an integer.

例子

当开始
[Light up the Color Sensor dimmer.]
设定 [Color 1 v] 灯亮为 (25)%
等待 (2) 秒
[Light up the Color Sensor brighter.]
设定 [Color 1 v] 灯亮为 (100)%

颜色找到了一个物体?#

The Color found an object? Boolean block reports 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.

<[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) 行

颜色检测颜色?#

The Color detects color? Boolean block reports 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.

<[Color 1 v] 测得 [红色 v]?>

参数

描述

颜色传感器

使用哪种颜色传感器,在设备窗口中配置。

颜色

Which color to check for:

  • red - Hue value between 340° and 20°
  • green - Hue value between 80° and 140°
  • blue - Hue value between 201° and 240°
  • white
  • yellow - Hue value between 40° and 59°
  • orange - Hue value between 25° and 30°
  • purple - Hue value between 280° and 320°
  • red violet - Hue value between 320° and 340°
  • violet
  • blue violet - Hue value between 240° and 280°
  • blue green - Hue value between 141° and 200°
  • yellow green - Hue value between 60° and 80°
  • yellow orange - Hue value between 30° and 39°
  • red orange - Hue value between 20° and 25°

例子

当开始
[Turn until the Color Sensor detects green.]
[右 v] 转
等到 <[Color 1 v] 测得 [绿色 v]?>
驱动停止

颜色颜色名称#

The Color color name reporter block reports the name of the color detected by the Color Sensor as a String.

可能的颜色有:

  • red

  • green

  • blue

  • white

  • yellow

  • orange

  • purple

  • red violet

  • violet

  • blue violet

  • blue green

  • yellow green

  • yellow orange

  • red orange

**注意:**此模块可以插入到 设置触摸 LED 颜色 模块 中,使触摸 LED 与检测到的颜色相匹配。

([Color 1 v] 颜色)

参数

描述

颜色传感器

使用哪种颜色传感器,在设备窗口中配置。

例子

当开始
[Stop and print when the Color Sensor detects green.]
[右 v] 转
等到 <[Color 1 v] 测得 [绿色 v]?>
驱动停止
在 [Brain v] 上打印 ([Color 1 v] 颜色) ◀ 并设定光标为下一行

颜色亮度#

The Color brightness reporter block reports how bright the detected color is, as a percentage from 0% to 100%.

A higher percentage means the Color Sensor detects more light. A lower percentage means the Color Sensor detects less light.

([Color 1 v] 亮度百分比)

参数

描述

颜色传感器

使用哪种颜色传感器,在设备窗口中配置。

例子

当开始
[Stop and print the brightness when the Color Sensor detects green.]
[右 v] 转
等到 <[Color 1 v] 测得 [绿色 v]?>
驱动停止
在 [Brain v] 上打印 ([Color 1 v] 亮度百分比) ◀ 并设定光标为下一行

色调#

The Color hue reporter block reports the hue detected by the Color Sensor as a number from 0 to 359 degrees.

Hue is a way to describe color using numbers around a color wheel, as shown below:

圆形色轮,显示全光谱色调,周边标有度数值,从顶部的 0° 到 360°,以 30 度为增量增加。

([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) 秒