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 |
|---|---|
|
The 3-Wire Port that the Light Sensor is connected to, whether it’s a port on the |
A Brain or 3-Wire Expander must be created first before they can be used to create an object with the Light Class constructor.
# 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 |
|---|---|
|
Optional. The only valid unit for brightness is |
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 |
|---|---|
|
La función de devolución de llamada que se llamará cuando cambie el valor del sensor de luz. |
|
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)