Potenciómetro V2#
Inicializando la clase PotentiometerV2#
Un PotenciómetroV2 se crea utilizando el siguiente constructor:
PotentiometerV2(port)
Este constructor utiliza un parámetro:
Parámetro |
Descripción |
---|---|
|
El puerto de 3 cables al que está conectado el potenciómetro V2, 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 clase PotentiometerV2.
# Create the Brain.
brain = Brain()
# Construct a PotentiometerV2 "pot2" with the PotentiometerV2 class.
pot2 = PotentiometerV2(brain.three_wire_port.a)
This pot2
object will be used in all subsequent examples throughout this API documentation when referring to PotentiometerV2 class methods.
Métodos de clase#
angle()#
The angle(units)
method returns the angle measured by the PotentiometerV2.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid RotationUnits type or |
Devuelve: El ángulo medido por el potenciómetro V2.
# Print the current angle of the PotentiometerV2 to the Brain's screen.
brain.screen.print(pot2.angle())
changed()#
The changed(callback, arg)
method registers a callback function for when the value measured by the PotentiometerV2 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 potentiometerV2_changed()
def potentiometerV2_changed():
# The Brain will print that the potentiometer value changed
# on the Brain's screen.
brain.screen.print("potentiometer value changed")
# Run PotentiometerV2_changed when the value measured by
# the Potentiometer changes.
pot2.changed(potentiometerV2_changed)