[esp32]Micorpython进行PWM

通过wokwi进行模拟PWM

from machine import PWM,ADC,Pin
import time
led_blue1=PWM(Pin(2),freq=1000)#把GPIO2定义为PWM输出,脉冲频率为1秒1000个
led_blue1.duty(1023)
btn1=Pin(35)
liangdu=0
while(1):
    if(btn1.value()==0):#有按钮按下
       time.sleep(1)  #延时1秒
       liangdu=liangdu+50
       print('按钮按下',liangdu)
       if(liangdu>=1024):
        liangdu=0
    led_blue1.duty(liangdu) #设置PWM调整亮度    

[esp32]Micorpython进行PWM_第1张图片

你可能感兴趣的:(python)