Sensor de luz#

Introducción#

El sensor de luz mide el brillo de la luz reflejada por un objeto o que incide sobre él. Emite un valor analógico que representa la cantidad de luz detectada.

El sensor de luz VEX EXP.

This page uses light_sensor as the example Light Sensor name. Replace it with your own configured name as needed.

A continuación se muestra una lista de los métodos disponibles:

  • brightness – Returns the amount of light detected by the Light Sensor.

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

Constructor: Inicializa manualmente un sensor de luz.

  • Light – Create a Light Sensor.

brillo#

brightness returns the amount of light detected by the Light Sensor as an integer.

Usage:
light_sensor.brightness(units)

Parámetro

Descripción

units

Optional. The unit to return the brightness with: PERCENT (default).

cambió#

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

Usage:
light_sensor.changed(callback, arg)

Parámetros

Descripción

callback

Una función definida previamente que se ejecuta cuando cambia el valor de brillo del sensor de luz.

arg

Optional. A tuple containing arguments to pass to the callback function. See Functions with Parameters for more information.

def my_function():
  brain.screen.print("Brightness changed")

# Call my_function whenever the brightness changes
light_sensor.changed(my_function)

Constructor#

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)

Parámetro

Descripción

port

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

  • On the EXP 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)