類比輸入#
介紹#
analog_in 類別用於讀取連接到 VEX V5 三線連接埠的裝置的類比輸入訊號。它提供對當前模擬值的訪問,並允許註冊回調函數以處理值的變化。
類別建構函數#
analog_in(
triport::port &port );
類別析構函數#
銷毀 analog_in 物件並釋放相關資源。
~analog_in();
參數#
範圍 |
類型 |
描述 |
|---|---|---|
|
|
類比輸入連接的 3 線端口,寫成 |
例子#
// Create the analog_in instance on 3-Wire Port A
analog_in AnalogInA = analog_in(Brain.ThreeWirePort.A);
成員功能#
analog_in 類別包含以下成員函數:
在呼叫 analog_in 函數之前,必須先建立 analog_in 實例,如下所示:
/* 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 );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
表示值的單位:
pct )百分比 |
此函數傳回模擬輸入的當前值。
Examples// Get the current value of the Analog Input
int32_t value = AnalogInA.value();
changed#
註冊一個回調函數,當模擬輸入值發生變化時,該函數將被呼叫。
Available Functionsvoid changed( void (* callback)(void) );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
當類比輸入值發生變化時,將呼叫該函數。 |
此函數不傳回值。
Examples定義回呼函數(在
int main()之外)// Display a message when the input changes void AnalogInputChanged() { Brain.Screen.print("analog input changed"); }在
int main()中註冊回呼函數int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Run AnalogInputChanged when the value of the // Analog Input changes AnalogInA.changed(AnalogInputChanged); }