Potenciómetro#
Inicializando la clase de potenciómetro#
Un potenciómetro se crea utilizando el siguiente constructor:
Potentiometer(port)
Este constructor utiliza un parámetro:
Parámetro |
Descripción |
---|---|
|
El puerto de 3 cables al que está conectado el potenciómetro, ya sea un puerto en el Cerebro o un Expandedor de 3 cables. |
Primero se debe crear un Cerebro o un Expansor de 3 cables antes de poder usarlos para crear un objeto con el constructor de la clase Potenciómetro.
# Create the Brain.
brain = Brain()
# Construct a Potentiometer "pot" with the Potentiometer class.
pot = Potentiometer(brain.three_wire_port.a)
This pot
object will be used in all subsequent examples throughout this API documentation when referring to Potentiometer class methods.
Métodos de clase#
angle()#
The angle(units)
method returns the angle measured by the Potentiometer.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid RotationUnits type or |
Devuelve: El ángulo medido por el potenciómetro
# Print the current angle of the Potentiometer to the
# Brain's screen.
brain.screen.print(pot.angle())
changed()#
The changed(callback, arg)
method registers a callback function for when the value measured by the Potentiometer changes.
Parámetros |
Descripción |
---|---|
llamar de vuelta |
La función de devolución de llamada que se llamará cuando cambie el valor medido por el potenciómetro. |
arg |
Opcional. Una tupla de argumentos para pasar a la función de devolución de llamada. |
Devoluciones: Ninguna.
# Define a function potentiometer_changed().
def potentiometer_changed():
# The Brain will print that the Potentiometer value changed
# on the Brain's screen.
brain.screen.print("potentiometer changed")
# Run potentiometer_changed when the value measured by
# the Potentiometer changes.
pot.changed(potentiometer_changed)