from machine import Pin, PWM
import time
# Configure the LED pin and set it as an output
led_pin = Pin(15, Pin.OUT) # Replace with the appropriate GPIO pin number
# Create a PWM object with a frequency of 1000 Hz
pwm = PWM(led_pin, freq=1000)
# Gradually increase brightness
for duty in range(0, 65536, 1024):
pwm.duty_u16(duty)
time.sleep(0.01) # Small delay for visual effect
# Gradually decrease brightness
for duty in range(65535, -1, -1024):
pwm.duty_u16(duty)
time.sleep(0.01) # Small delay for visual effect
# Turn off the LED
pwm.deinit()