import machine
import time
# Define the pin for the LED
led_pin = machine.Pin(5, machine.Pin.OUT) # Assuming pin 5 for the LED
# Create a PWM object
pwm = machine.PWM(led_pin)
# Set the PWM frequency (in Hz)
pwm.freq(1000) # Adjust as needed
while True:
# Increase brightness to maximum
for duty_cycle in range(1024):
pwm.duty(duty_cycle)
time.sleep(0.005) # Adjust the delay for desired fade speed
# Set to maximum brightness (100%) and hold for 5 seconds
pwm.duty(1023)
time.sleep(5) # Hold at maximum brightness for 5 seconds
# Decrease brightness to 50%
for duty_cycle in range(1023, 512, -1): # Fade from 100% to 50%
pwm.duty(duty_cycle)
time.sleep(0.005) # Adjust the delay for desired fade speed
# Set brightness to 50% and hold for 5 seconds
pwm.duty(512) # 50% brightness
time.sleep(5) # Hold at 50% brightness for 5 seconds