光传感器#
介绍#
The light class is used to measure the brightness detected by the Light Sensor.
类构造函数#
light(
triport::port &port );
类析构函数#
Destroys the light object and releases associated resources.
virtual ~light();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
The 3-Wire Port that the Light Sensor is connected to, written as |
示例#
// Create a light instance in Port A
light LightA = light(Brain.ThreeWirePort.A);
成员功能#
The light class includes the following member functions:
brightness— Returns the brightness detected by the Light Sensor.
Before calling any light member functions, a light instance must be created, as shown below:
/* 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 );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The unit that represents the brightness:
|
Returns an int32_t representing the brightness measured by the Light Sensor as a percent in the range 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);