PWM-呼吸燈-mpython
tags: micropython
所需零件
- ESP32
- 5mm LED
- 330 歐姆電阻
- 麵包板
- 跳線
程式碼
參照–我的micropython函式筆記本
from machine import Pin, PWM
from time import sleep
led = PWM(Pin(4), freq=5000)
while True:
for duty_cycle1 in range(0, 1000, 10):
led.duty(duty_cycle1)
sleep(0.05)
for duty_cycle2 in range(1000, 0, -10):
led.duty(duty_cycle2)
sleep(0.05)