from machine import Pin, PWM
import utime
# Define RGB LED pins
common_pin = Pin(0, Pin.OUT) # GPIO pin 0
red_pin = Pin(1, Pin.OUT) # GPIO pin 1
green_pin = Pin(2, Pin.OUT) # GPIO pin 2
blue_pin = Pin(3, Pin.OUT) # GPIO pin 3
# Create PWM objects for smooth color blending
red_pwm = PWM(red_pin)
green_pwm = PWM(green_pin)
blue_pwm = PWM(blue_pin)
# Function to set RGB color with high brightness
def set_color(red, green, blue):
common_pin.value(1) # Turn on common pin
red_pwm.duty_u16(int(red * 65535 / 255))
green_pwm.duty_u16(int(green * 65535 / 255))
blue_pwm.duty_u16(int(blue * 65535 / 255))
# Main loop
while True:
# Red (high brightness)
set_color(255, 0, 0)
utime.sleep(1)
# Green (high brightness)
set_color(0, 255, 0)
utime.sleep(1)
# Blue (high brightness)
set_color(0, 0, 255)
utime.sleep(1)
Loading
pi-pico-w
pi-pico-w