PWM 輸出#

介紹#

pwm_out 類別用於控制 VEX V5 三線連接埠上的 PWM(脈衝寬度調變)輸出。它允許設備向相容的三線組件發送可變寬度的脈衝訊號。

類別建構函數#

pwm_out(
  triport::port &port );

類別析構函數#

銷毀 pwm_out 物件並釋放相關資源。

~pwm_out();

參數#

範圍

類型

描述

port

triport::port &

PWM 輸出連接到 3 線端口,寫成 Brain.ThreeWirePort.X 或 ExpanderName.X,其中 X 是端口字母(例如, Brain.ThreeWirePort.A 或 Expander1.A)。

例子#

// 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 Functions
void state(
  int32_t      value,
  percentUnits units );

Parameters

範圍

類型

描述

value

int32_t

PWM 輸出的新設定值,範圍從 -100% 到 +100%。

units

percentUnits

PWM 值的單位: percent / pct%

Return Values

此函數不傳回值。

Notes
  • PWM 輸出值範圍為 -100% 至 +100%。

  • PWM 輸出的唯一有效單位是 percent。

Examples
// Set the PWM Output to 50%
pwm.state(50, percent);

// Set the PWM Output to -75%
pwm.state(-75, percent);