Potentiometer#

Introduction#

The Potentiometer is an analog sensor that measures the angular position of a rotating shaft. It outputs a voltage proportional to its position.

Depending on the Potentiometer version, the amount of rotation it can detect varies:

  • Potentiometer – Up to 250 degrees

  • Potentiometer V2 – 330 degrees (Continuous)

The VEX V5 Potentiometer V1.

The VEX V5 Potentiometer V2.

Potentiometer

Potentiometer V2

This page uses potentiometer_a as the example Potentiometer name. Replace it with your own configured name as needed.

Below is a list of available methods:

  • angle – Reports the angular position of the Potentiometer in degrees or as a percent.

  • changed – Registers a function to be called whenever the Potentiometer’s value changes.

Constructors – Manually initialize a Potentiometer or Potentiometer V2.

angle#

angle returns the angular position of the Potentiometer.

Usage:
potentiometer_a.angle(units)

Parameter

Description

units

The unit of measurement:

  • DEGREES (default)
    • 0.0 to 250.0 for a Potentiometer
    • 0.0 to 330.0 for a Potentiometer V2
  • PERCENT – The position as a percentage of full rotation (0 to 100%)

changed#

changed registers a function to be called whenever the Potentiometer’s value changes.

Usage:
changed(callback, arg)

Parameters

Description

callback

A previously defined function that executes when the Potentiometer’s value changes.

arg

Optional. A tuple containing arguments to pass to the callback function. See Functions with Parameters for more information.

def my_function():
  brain.screen.print("Value changed!")

# Call my_function whenever potentiometer_a's angle changes
potentiometer_a.changed(my_function)

Constructors#

Constructors are used to manually create PotentiometerV2 and Potentiometer objects, which are necessary for configuring Potentiometers outside of VEXcode.

PotentiometerV2#

PotentiometerV2 creates a V5 Potentiometer V2.

Usage:
PotentiometerV2(port)

Parameter

Description

port

The 3-Wire Port that the Potentiometer V2 is connected to:

  • On the V5 Brainbrain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expanderexpander.a where expander is the name of the expander instance.

# Create a Potentiometer V2 in Port A
potentiometer_a = PotentiometerV2(brain.three_wire_port.a)

Potentiometer#

Potentiometer creates a Potentiometer.

Usage:
Potentiometer(port)

Parameter

Description

port

The 3-Wire Port that the Potentiometer is connected to:

  • On the V5 Brainbrain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expanderexpander.a where expander is the name of the expander instance.

# Create a Potentiometer in Port A
potentiometer_a = Potentiometer(brain.three_wire_port.a)