模拟输入#
介绍#
The analog_in class is used to read analog input signals from devices connected to a VEX V5 3-Wire port. It provides access to the current analog value and allows callback functions to be registered for value changes.
类构造函数#
analog_in(
triport::port &port );
类析构函数#
Destroys the analog_in object and releases associated resources.
~analog_in();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
The 3-Wire Port that the Analog Input is connected to, written as |
例子#
// Create the analog_in instance on 3-Wire Port A
analog_in AnalogInA = analog_in(Brain.ThreeWirePort.A);
成员功能#
The analog_in class includes the following member functions:
changed— Registers a callback function for when the analog input value changes.
Before calling any analog_in member functions, an analog_in instance must be created, as shown below:
/* This constructor is required to use an
Analog Input device. Replace the values
as needed. */
// Create the analog_in instance on 3-Wire Port A
analog_in AnalogInA = analog_in(Brain.ThreeWirePort.A);
value#
返回模拟输入的当前值。
Available Functionsint32_t value(
analogUnits units );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The unit to represent the value:
|
该函数返回模拟输入的当前值。
Examples// Get the current value of the Analog Input
int32_t value = AnalogInA.value();
changed#
注册一个回调函数,当模拟输入值发生变化时,该函数将被调用。
Available Functionsvoid changed( void (* callback)(void) );
范围 |
类型 |
描述 |
|---|---|---|
|
|
当模拟输入值发生变化时,将调用该函数。 |
此函数不返回值。
Examples// Display a message when the input changes
void AnalogInputChanged() {
Brain.Screen.print("analog input changed");
}
// Run AnalogInputChanged when the value of the
// Analog Input changes
AnalogInA.changed(AnalogInputChanged);