potV2#

Initializing the potV2 Class#

A PotentiometerV2 is created by using the following constructor:

The potV2 constructor creates a potV2 object in the specified Three Wire Port:

Parameter

Description

port

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 potV2 Class constructor.

// Create the Brain.
brain Brain;
// Construct a PotentiometerV2 "potentiometerV2" with the potV2 class.
potV2 potentiometerV2 = potV2(Brain.ThreeWirePort.A);

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

Class Methods#

angle()#

The angle(units) method returns the angle measured by the PotentiometerV2.

Parameters

Description

units

A valid RotationUnit or percent. The default is degrees.

Returns: A double representing the angle measured by the PotentiometerV2 in the specified units.

// Get the current angle of the PotentiometerV2 in the
// range 0 - 250 degrees.
double angle = potentiometerV2.angle(degrees);

// Print the current angle of the PotentiometerV2 to the
// Brain's screen.
Brain.Screen.print(angle);

changed()#

The changed(callback) 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 PotentiometerV2 changes.

Returns: None.

// Define the potentiometerChanged function with a void
// return type, showing it doesn't return a value.
void potentiometerChanged() {
  // The brain will print that the value of the PotentiometerV2
  // changed on the Brain's screen.
  Brain.Screen.print("PotentiometerV2 changed");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run potentiometerChanged when the value measured by
  // the PotentiometerV2 changes.
  potentiometerV2.changed(potentiometerChanged);
}