#

初始化pot类#

使用以下构造函数创建电位器:

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

范围

描述

端口

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

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

// Create the Brain.
brain Brain;
// Construct a Potentiometer "potentiometer" with the
// pot class.
pot potentiometer = pot(Brain.ThreeWirePort.A);

当引用 pot 类方法时,此“电位器”对象将在整个 API 文档的所有后续示例中使用。

类方法#

角度()#

angle(units) 方法返回电位器测量的角度。

参数

描述

单位

有效的 rotationUnitpercent。默认值为 degrees

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

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

// Print the current angle of the Potentiometer to the
// brain screen.
Brain.Screen.print(angle);

已更改()#

changed(callback) 方法注册一个回调函数,用于当电位器测量的值发生变化时。

参数

描述

打回来

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

**返回:**无。

// 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 Potentiometer
  // changed on the Brain's screen.
  Brain.Screen.print("Potentiometer changed");
}

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

  // Run PotentiometerChanged when the value measured by
  // the Potentiometer changes.
  potentiometer.changed(potentiometerChanged);
}