PWM 输出#
介绍#
pwm_out 类用于控制 VEX V5 三线端口上的 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);