代码: 全选
from machine import Pin
from esp32 import MCPWM
pwm0 = PWM(0) # Create MCPWM object with timer ID (0..5)
pwm0.bind(Pin(5)) # Bind to output Pin
pwm0.freq(500) # Set frequency in Hz
pwm0.freq() # Get achieved frequency
pwm0.duty(20) # Set duty in percent
pwm0.duty() # Get achieved duty
pwm0.start() # Start/resume output
pwm0.stop() # Stop output
https://github.com/bskp/micropython_esp32_mcpwm