from machine import Pin, PWM
import time
LED = 25 # For ESP32
pwm_led = PWM(Pin(LED, mode=Pin.OUT)) # Attach PWM object on the LED pin
pwm_led.freq(1_000)
while True:
for duty in range(100): # Duty from 0 to 100 %
pwm_led.duty(int((duty/100)*1024))
print("Duty % =", duty)
time.sleep_ms(50)