#

要使 pot 命令出现在 VEXcode V5 中,必须在“设备”窗口中配置 3 线电位器。

更多信息,请参阅以下文章:

初始化 pot 类#

电位器可以通过以下构造函数创建:

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

范围

描述

port

The 3-Wire Port that the Potentiometer 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 pot Class constructor.

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

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

类方法#

angle()#

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

参数

描述

units

A valid rotationUnit or percent. The default is 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()#

The changed(callback) method registers a callback function for when the value measured by the Potentiometer changes.

参数

描述

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