Luz#

Inicializando la clase Light#

Un sensor de luz se crea utilizando el siguiente constructor:

Light(port)

Este constructor utiliza un parámetro:

Parámetro

Descripción

port

El puerto de 3 cables al que está conectado el sensor de luz, ya sea un puerto en el Cerebro o un Expandedor de 3 cables.

Primero se debe crear un Brain o un 3-Wire Expander antes de poder usarlos para crear un objeto con el constructor de la clase Light.

# Create the Brain.
brain = Brain()
# Construct a Light Sensor "light" with the Light class.
light = Light(brain.three_wire_port.a)

This light object will be used in all subsequent examples throughout this API documentation when referring to Light class methods.

Métodos de clase#

brightness()#

The brightness(units) method returns the brightness level of light falling on the Light Sensor. The brightness of the Light Sensor is an estimation based on the raw value of the sensor.

Un brillo del 0 % es un valor bruto de 900 o superior. Un brillo del 100 % es un valor bruto de 0.

Parámetros

Descripción

unidades

Optional. The only valid unit for brightness is PERCENT.

Devoluciones: El nivel de brillo del sensor de luz en el rango de 0% - 100%.

# Get Light Sensor brightness in range of 0% - 100%.
value = light.brightness()

changed()#

The changed(callback, arg) method registers a callback function for when the value of the Light Sensor changes.

Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.

Parámetros

Descripción

llamar de vuelta

La función de devolución de llamada que se llamará cuando cambie el valor del sensor de luz.

arg

Opcional. Una tupla de argumentos para pasar a la función de devolución de llamada.

Devoluciones: Ninguna.

# Define a function light_changed()
def light_changed():
    # The Brain will print that the Light Sensor value changed 
    # on the Brain's screen.
    brain.screen.print("Light Sensor value changed")
# Run light_changed when the value of this Light Sensor changes.
light.changed(light_changed)