import machine
import utime
# Configure PWM parameters
PWM_PIN = 19 # Change this to the desired PWM output pin
PWM_FREQ_HZ = 50000 # Set the desired PWM frequency in Hz
DUTY_CYCLE_PERCENT = 50 # Set the duty cycle as a percentage (0-100)
# Initialize PWM on the specified pin
pwm = machine.PWM(machine.Pin(PWM_PIN), freq=PWM_FREQ_HZ)
try:
while True:
# Vary the duty cycle to create a pulsating PWM signal
for duty_cycle in range(0, 101, 5):
pwm.duty(duty_cycle) # Set the duty cycle
utime.sleep(0.1) # Delay for a short period
# Reverse the duty cycle to go from 100% to 0%
for duty_cycle in range(100, -1, -5):
pwm.duty(duty_cycle)
utime.sleep(0.1)
except KeyboardInterrupt:
pass
# Turn off PWM and release the pin
pwm.deinit()