Ameba MicroPython: [RTL8722CSM] [RTL8722DM] PWM - LED 渐变
材料准备
- Ameba x 1, LED x 1, 电阻(220欧姆) x 1
范例说明
PWM脉宽调变控制输出脉波周期来实现对LED亮度和马达的控制。下面是我们用LED来展示PWM是如何来实做的。
连接PA_26至LED的正极和电阻串联在一起, 然后GND接至LED负极。如图
然后, 逐行复制下面的代码去REPL并观察结果, LED会慢慢的渐变明亮。
from machine import Pin, PWM import time p = PWM(pin = "PA_26") # 0 duty cycle thus output 0 p.write(0.0) # 10% duty cycle p.write(0.1) # 50% duty cycle p.write(0.5) # 100% duty cycle p.write(1.0)
Realtek IoT/Wi-Fi MCU Solutions . All Rights Reserved. 使用条款