PWM 輸出#
介紹#
pwm_out 類別用於控制 VEX EXP 三線連接埠上的 PWM(脈衝寬度調變)輸出。它允許設備向相容的三線組件發送可變寬度的脈衝訊號。
類別建構函數#
pwm_out(
triport::port &port );
類別析構函數#
銷毀 pwm_out 物件並釋放相關資源。
~pwm_out();
參數#
範圍 |
類型 |
描述 |
|---|---|---|
|
|
PWM 輸出連接到 3 線端口,寫成 |
例子#
// Create the pwm_out instance on 3-Wire Port A
pwm_out pwm = pwm_out(Brain.ThreeWirePort.A);
成員功能#
pwm_out 類別包含以下成員函數:
state— 設定 PWM 輸出的狀態。
在呼叫任何 pwm_out 函數之前,必須先建立一個 pwm_out ,如下所示:
/* This constructor is required when using VS Code.
PWM configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create the pwm_out instance on 3-Wire Port A
pwm_out pwm = pwm_out(Brain.ThreeWirePort.A);
state#
將PWM輸出狀態設定為指定值。
Available Functionsvoid state(
int32_t value,
percentUnits units );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
PWM 輸出的新設定值,範圍從 -100% 到 +100%。 |
|
|
PWM 值的單位: |
此函數不傳回值。
NotesPWM 輸出值範圍為 -100% 至 +100%。
PWM 輸出的唯一有效單位是
percent。
// Set the PWM Output to 50%
pwm.state(50, percent);
// Set the PWM Output to -75%
pwm.state(-75, percent);