PotentiometerV2#
Initializing the PotentiometerV2 Class#
A PotentiometerV2 is created by using the following constructor:
PotentiometerV2(port)
This constructor uses one parameter:
Parameter |
Description |
---|---|
|
The 3-Wire Port that the PotentiometerV2 is connected to, whether it’s a port on the Brain, or a 3-Wire Expander. |
A Brain or 3-Wire Expander must be created first before they can be used to create an object with the PotentiometerV2 Class constructor.
# 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.
Class Methods#
angle()#
The angle(units)
method returns the angle measured by the PotentiometerV2.
Parameters |
Description |
---|---|
units |
Optional. A valid RotationUnits type or |
Returns: The angle measured by the PotentiometerV2.
# 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.
Parameters |
Description |
---|---|
callback |
The callback function to be called when the value measured by the potentiometer changes. |
arg |
Optional. A tuple of arguments to pass to the callback function. |
Returns: None.
# 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)