光传感器#
介绍#
light 类与光传感器配合使用,光传感器用于测量物体反射或照射到物体上的光的亮度。它输出一个模拟值,表示检测到的光量。

类构造函数#
light(
triport::port &port );
类析构函数#
摧毁 light 对象并释放相关资源。
virtual ~light();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
光传感器连接的 3 线端口,写成 |
示例#
// Create a light instance in Port A
light LightA = light(Brain.ThreeWirePort.A);
成员功能#
light 类包含以下成员函数:
brightness— 返回光传感器检测到的光量。
在调用任何 light 成员函数之前,必须先创建一个 light 实例,如下所示:
/* This constructor is required when using VS Code.
Light Sensor configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a light instance in Port A
light LightA = light(Brain.ThreeWirePort.A);
brightness#
返回光传感器检测到的光量。这可用于检查物体是否足够明亮,以便准确地报告其他视觉数据。
Available Functionsint32_t brightness(
percentUnits units = percentUnits::pct );
范围 |
类型 |
描述 |
|---|---|---|
|
|
亮度单位: |
返回一个 int32_t ,表示光传感器测量的亮度,以百分比表示,范围为 0 - 100%。
// Get Light Sensor brightness in range of 0% - 100%.
int32_t value = LightA.brightness();
// Print the brightness of the Light Sensor to the
// Brain's screen.
Brain.Screen.print(value);