模拟输入#
初始化analog_in类#
使用以下构造函数创建模拟输入:
The analog_in constructor creates an analog_in object in the specified Three Wire Port.
范围 |
描述 |
|---|---|
|
The 3-Wire Port that the Analog Input is connected to, whether it’s a port on the |
A Brain or 3-Wire Expander must be created first before they can be used to create an object with the analog_in Class constructor.
// 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);
}