模拟输入#

初始化analog_in类#

使用以下构造函数创建模拟输入:

The analog_in constructor creates an analog_in object in the specified Three Wire Port.

范围

描述

port

模拟输入连接到的 3 线端口,无论它是 Brain 上的端口,还是 3 线扩展器 上的端口。

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

// Create the Brain.
brain Brain;
// Construct an analog_in "analogIn" with the
// analog_in class.
analog_in analogIn = analog_in(Brain.ThreeWirePort.A);

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

类方法#

changed()#

The changed(callback) method registers a function to be called when the value of the analog input changes.

参数

描述

打回来

当模拟输入值发生变化时调用的函数。

**返回:**事件类的一个实例。

// Define the AnalogInputChanged function with a void return
// type, showing it doesn't return a value.
void AnalogInputChanged() {
  // The Brain will print that the Analog Input changed on
  // the Brain's screen.
  Brain.Screen.print("analog input changed");
}

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

  // Run analogInputChanged when the value of the
  // Analog Input changes.
  analogIn.changed(analogInputChanged);
}