#hardware platform: Ai-Thinker-ESP-C3-32S-Kit
#author: Aviolet
#Result: pwm
#The information below shows pwm is unavailble for the current version.
#Except the connection between IO3 IO4 IO5 and onboard LED, test pwm function.
import machine #upload esp32 machine
import time, math #upload time,math
led_red = machine.PWM(machine.Pin(3), freq=100) #set GPIO PWM frequency PIN red_led
led_green = machine.PWM(machine.Pin(4), freq=500) #set GPIO PWM frequency PIN green_led
led_blue = machine.PWM(machine.Pin(5), freq=1000) #set GPIO PWM frequency PIN blue_led
def pulse(l, t): #Define functions
for i in range(20): #for loop
l.duty(int(math.sin(i / 10 * math.pi) * 500 + 500)) #set PWM parameter duty
time.sleep_ms(t) #set PWM parameter polar
while True:
pulse(led_red, 10) #downloads pwm parameters
pulse(led_green, 20) #downloads pwm parameters
pulse(led_blue, 30) #
【阿紫学嵌入式】ESP32C3-kit Micropython开发PWM实例代码 Thonny IDE
最新推荐文章于 2024-05-08 11:49:31 发布