from machine import Pin, PWM
from time import sleep_ms
 

led = Pin(4)
pwm_led = PWM(led)

while 1:
    for i in range(1023, -1, -1):
        pwm_led.duty(i)
        sleep_ms(1)
    for i in range(1024):
        pwm_led.duty(i)
        sleep_ms(1)