potV2#

初始化 potV2 类#

使用以下构造函数创建 PotentiometerV2:

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

范围

描述

port

电位器 V2 连接到的 3 线端口,无论它是 Brain 上的端口,还是 3 线扩展器 上的端口。

必须先创建 Brain3-Wire Expander,然后才能使用 potV2 类构造函数创建对象。

// 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.

类方法#

angle()#

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

参数

描述

单位

A valid rotationUnit or percent. The default is degrees.

**返回:**以指定单位表示 PotentiometerV2 测量的角度的双精度值。

// 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.

参数

描述

打回来

当 PotentiometerV2 测量的值发生变化时调用的回调函数。

**返回:**无。

// 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);
}