脉宽调制#
初始化 Pwm 类#
使用以下构造函数创建 Pwm 输出:
Pwm(port)
此构造函数使用一个参数:
范围 |
描述 |
---|---|
|
必须先创建 Brain 或 3-Wire Expander,然后才能使用 Pwm 类构造函数创建对象。
# Create the Brain.
brain = Brain()
# Construct a Pwm Output "pwm" with the Pwm class.
pwm = Pwm(brain.three_wire_port.a)
This pwm
object will be used in all subsequent examples throughout this API documentation when referring to Pwm class methods.
类方法#
state()#
The state(value, units)
method sets the state of the PWM.
参数 |
描述 |
---|---|
价值 |
为 PWM 输出设置的新值,从 -100% 到 +100%。 |
单位 |
Optional. The only valid unit for pwm output is |
**返回:**无。
# Set PWM output to 50%.
pwm.state(50)