RGB Led Pico

Input a hex colour code, and watch the LED transform your space with vibrant, customizable lighting. Unleash your creativity effortlessly!"
Supplies
Principle

An RGB LED module can produce almost any colour using these three primary additive colours: Red, Green and Blue. The simplest version of an RGB LED has a combination of 3 separate light-emitting diodes in one package, housed under a clear protective lens
Schematic Diagram


-connect - to gnd
-connect B to gp 4
-connect G to gp 3
-connect R to gp 2
Source Code

this code prompts the user for a A hex color code and turns the led that colour
import machine
RED_PIN = 2
GREEN_PIN = 3
BLUE_PIN = 4
red_pwm = machine.PWM(machine.Pin(RED_PIN))
green_pwm = machine.PWM(machine.Pin(GREEN_PIN))
blue_pwm = machine.PWM(machine.Pin(BLUE_PIN))
# Function to set the RGB LED color based on a hex value with brightness
def set_led_color(hex_color, brightness=1.0):
red = ((hex_color >> 16) & 0xFF) * brightness
green = ((hex_color >> 8) & 0xFF) * brightness
blue = (hex_color & 0xFF) * brightness
red_pwm.duty_u16(int(red * 255)) # Scale to 16-bit PWM (0-65535)
green_pwm.duty_u16(int(green * 255))
blue_pwm.duty_u16(int(blue * 255))
while True:
try:
# Input a hex color value with #
hex_color_input = input("Enter a hex color value : ")
if hex_color_input.startswith('#'):
hex_color = int(hex_color_input[1:], 16)
set_led_color(hex_color)
else:
print("Invalid input format. Please use '#' followed by a valid hex color.")
except ValueError:
print("Invalid input. Please enter a valid hex color value.")
Colour

you can use this handy HTML program to help you choose a colour