from machine import Pin, PWM
from time import sleep
pwm = PWM(Pin(15))
pwm.freq(1000)
while True:
for duty in range(0, 65535, 50):
pwm.duty_u16(duty)
sleep(0.001)
for duty in range(65535, 0, -50):
pwm.duty_u16(duty)
sleep(0.001)