from machine import Pin, PWM
import time
# Define the RGB LED pins
red_pin = 14 # Replace with the appropriate GPIO pin for the red LED
green_pin = 12 # Replace with the appropriate GPIO pin for the green LED
blue_pin = 13 # Replace with the appropriate GPIO pin for the blue LED
# Create PWM objects for each color
red_pwm = PWM(Pin(red_pin), freq=1000)
green_pwm = PWM(Pin(green_pin), freq=1000)
blue_pwm = PWM(Pin(blue_pin), freq=1000)
def set_color(red, green, blue):
red_pwm.duty(int(red * 1023 / 255))
green_pwm.duty(int(green * 1023 / 255))
blue_pwm.duty(int(blue * 1023 / 255))
def cycle_colors():
delay = 0.08
for i in range(255):
set_color(i, 0, 255 - i)
time.sleep(delay)
for i in range(255):
set_color(255 - i, i, 0)
time.sleep(delay)
for i in range(255):
set_color(0, 255 - i, i)
time.sleep(delay)
try:
while True:
cycle_colors()
except KeyboardInterrupt:
# Turn off the LEDs before exiting
set_color(0, 0, 0)