數位輸入#
介紹#
V5 Brain 的 digital_in 類別允許其讀取來自外部來源(例如開關或感測器)的數位訊號。它會偵測輸入線是高電平(接收 5 伏特電壓)還是低電平(接收到 0 伏特電壓)。這可用於確定開/關狀態或觸發專案中的事件。
類別建構函數#
digital_in(
triport::port &port );
類別析構函數#
銷毀 digital_in 物件並釋放相關資源。
~digital_in();
參數#
範圍 |
類型 |
描述 |
|---|---|---|
|
|
數位輸入設備連接的 3 線端口,寫成 |
例子#
// Create the digital_in instance on 3-Wire Port A
digital_in digin = digital_in(Brain.ThreeWirePort.A);
成員功能#
數字輸入類別 digital_in 函數:
value— 傳回數位輸入埠是否接收到高電位或低電位訊號。high— 註冊一個函數,當數位輸入裝置發送高訊號時,函數將會被呼叫。low— 註冊一個函數,當數位輸入裝置發送低電平訊號時,該函數將被呼叫。
在呼叫任何 digital_in 函數之前,必須先建立一個 digital_in ,如下所示:
/* This constructor is required when using VS Code.
Digital input configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create the digital_in instance on 3-Wire Port A
digital_in DigitalInA = digital_in(Brain.ThreeWirePort.A);
value#
返回數位輸入埠接收到的是高電平訊號還是低電平訊號。
可用功能
int32_t value();
參數
此函數不接受任何參數。
傳回值
傳回一個表示當前數位訊號狀態的 int32_t:
1– 數位輸入埠接收到高電平訊號(約 5V)。0– 數位輸入埠接收到低訊號(約 0V)。
high#
註冊一個函數,當數位輸入裝置發送高電平訊號(約 5V)時,該函數將被呼叫。
Available Functionsvoid high(
void (* callback)(void) );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
當輸入為高電位時將呼叫的函數。 |
此函數不傳回值。
Examples定義回呼函數(在
int main()之外)// Display that the input is high void inputHigh() { Brain.Screen.print("digital input high"); }在
int main()中註冊回呼函數int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Run inputHigh when the Digital Input is high DigitalInA.high(inputHigh); }
low#
註冊一個函數,當數位輸入裝置發送低訊號(約 0V)時,該函數將被呼叫。
Available Functionsvoid low(
void (* callback)(void) );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
當輸入為低電位時將呼叫的函數。 |
此函數不傳回值。
Examples定義回呼函數(在
int main()之外)// Display that the input is low void inputLow() { Brain.Screen.print("digital input low"); }在
int main()中註冊回呼函數int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Run inputLow when the Digital Input is low DigitalInA.low(inputLow); }