脉宽调制输出#

初始化 pwm_out 类#

使用以下构造函数创建 PWM 输出:

pwm_out 构造函数在指定的三线端口中创建一个 pwm_out 对象:

范围

描述

端口

用于 Pwm 输出的 3 线端口,无论它是 Brain 上的端口,还是 3 线扩展器 上的端口。

必须先创建 Brain3-Wire Expander,然后才能使用 pwm_out 类构造函数创建对象。

// Create the Brain.
brain Brain;
// Construct a Pwm Output "pwm" with the Pwm class.
pwm_out pwm = pwm_out(Brain.ThreeWirePort.A);

当引用 pwm_out 类方法时,此“pwm”对象将在整个 API 文档的所有后续示例中使用。

类方法#

状态()#

state(value,units) 命令设置 PWM 的状态。

参数

描述

价值

为 PWM 输出设置的新值,从 -100% 到 +100%。

单位

pwm 输出的唯一有效单位是“百分比”。

**返回:**无。

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