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

This page uses light_sensor as the example Light Sensor name. Replace it with your own configured name as needed.
以下是可用方法列表:
brightness– Returns the amount of light detected by the Light Sensor as a percent.changed– Registers a function to be called whenever the Light Sensor’s brightness value changes.
构造函数 - 手动初始化光传感器。
Light– Create a Light Sensor.
亮度#
brightness returns the amount of light detected by the Light Sensor as an integer. This can be used to check if an object is bright enough to accurately report other visual data.
Usage:
light_sensor.brightness(units)
范围 |
描述 |
|---|---|
|
Optional. The unit to return the brightness with: |
已更改#
changed registers a function to be called whenever the Light Sensor’s brightness value changes.
Usage:
light_sensor.changed(callback, arg)
参数 |
描述 |
|---|---|
|
先前定义的 函数,当光传感器的亮度值发生变化时执行。 |
|
Optional. A |
def my_function():
brain.screen.print("Brightness changed")
# Call my_function whenever the brightness changes
light_sensor.changed(my_function)
构造函数#
Constructors are used to manually create Light objects, which are necessary for configuring a Light Sensor outside of VEXcode.
Light#
Light creates a Light Sensor.
Usage:
Light(port)
范围 |
描述 |
|---|---|
|
The 3-Wire Port that the Light Sensor is connected to:
|
# Create a Light Sensor in Port A
light_sensor = Light(brain.three_wire_port.a)