Light#

Introduction#

The Light Sensor measures the brightness of light reflected from or shining on an object. It outputs an analog value that represents how much light is detected.

The VEX V5 Light Sensor.

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

Below is a list of available methods:

  • 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.

Constructor – Manually initialize a Light Sensor.

  • Light – Create a Light Sensor.

brightness#

brightness returns the amount of light detected by the Light Sensor as a percent.

Usage:
light_sensor.brightness(units)

Parameter

Description

units

Optional. The unit to return the brightness with:

  • PERCENT (default)

changed#

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

Usage:
light_sensor.changed(callback, arg)

Parameters

Description

callback

A previously defined function that executes when the Light Sensor’s brightness value changes.

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)

Parameter

Description

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)