#

介绍#

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

VEX V5 光传感器。

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 a percent.

Usage:
light_sensor.brightness(units)

范围

描述

单位

Optional. The unit to return the brightness with:

  • PERCENT (default)

已更改#

changed registers a function to be called whenever the Light Sensor’s brightness value changes.

Usage:
light_sensor.changed(callback, arg)

参数

描述

callback

先前定义的 函数,当光传感器的亮度值发生变化时执行。

arg

可选。包含要传递给回调函数的参数的元组。有关更多信息,请参阅带参数的函数

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)

范围

描述

port

The 3-Wire Port that the Light Sensor is connected to:

  • On the V5 Brainbrain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expanderexpander.a where expander is the name of the expander instance.

# Create a Light Sensor in Port A
light_sensor = Light(brain.three_wire_port.a)