import machine
import time
# Define the GPIO pin connected to the LED
led_pin = 22 # You can change this to the GPIO pin you are using
# Create a PWM object
led_pwm = machine.PWM(machine.Pin(led_pin), freq=1000)
# Function to fade the LED in and out
def fade_led():
for duty_cycle in range(1023, -1, -10): # Fade in
led_pwm.duty(duty_cycle)
time.sleep_ms(20)
for duty_cycle in range(0, 1024, 10): # Fade out
led_pwm.duty(duty_cycle)
time.sleep_ms(20)
# Run the fading function in a loop
while True:
fade_led()