Entrada analógica#

Inicializando la clase AnalogIn#

Un objeto AnalogIn se crea utilizando el siguiente constructor:

AnalogIn(port)

Este constructor utiliza un parámetro:

Parámetro

Descripción

port

El puerto de 3 cables al que está conectado AnalogIn, ya sea un puerto en el Brain o un 3-Wire Expander.

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

# Create the Brain.
brain = Brain()
# Construct an AnalogIn "analog_in" with the
# AnalogIn class.
analog_in = AnalogIn(brain.three_wire_port.a)

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

Métodos de clase#

changed()#

The changed(callback, arg) method registers a function to be called when the value of the analog input changes.

Parámetros

Descripción

llamar de vuelta

Una función que se llamará cuando cambie el valor de la entrada analógica.

arg

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

Devuelve: Una instancia de la clase Event.

# Define the function analogIn_changed.
def analogIn_changed():
    # The Brain will print that the analog input 
    # changed on the Brain's screen.
    brain.screen.print("analog input changed")
# Run analogIn_changed when the value of the
# analog input changes.
analog_in.changed(analogIn_changed)

# Get the value of analog input in range 0 - 4095.
value = analog_in.value()

# Get the value of analog input in range 0 - 1023.
value = analog_in.value(AnalogUnits.TENBIT)