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);