potV2#

初始化 potV2 类#

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

potV2 构造函数在指定的三线端口中创建一个 potV2 对象:

范围

描述

端口

电位器 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);

当引用 potV2 类方法时,此 potiometerV2 对象将在整个 API 文档的所有后续示例中使用。

类方法#

角度()#

angle(units) 方法返回 PotentiometerV2 测量的角度。

参数

描述

单位

有效的 rotationUnitpercent。默认值为 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(callback) 方法注册一个回调函数,用于当 PotentiometerV2 测量的值发生变化时。

参数

描述

打回来

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