RGB Led Pico
![5e8eda6b-3030-4736-b6bd-cba0e1beaee9.gif](/proxy/?url=https://content.instructables.com/FCO/DVJG/LNABY3TL/FCODVJGLNABY3TL.gif&filename=5e8eda6b-3030-4736-b6bd-cba0e1beaee9.gif)
Input a hex colour code, and watch the LED transform your space with vibrant, customizable lighting. Unleash your creativity effortlessly!"
Supplies
Principle
![Color-Mixing-Subtractive-Additive.png](/proxy/?url=https://content.instructables.com/FLD/5EF9/LNABY44M/FLD5EF9LNABY44M.png&filename=Color-Mixing-Subtractive-Additive.png)
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
![Color-Mixing-Subtractive-Additive.png](/proxy/?url=https://content.instructables.com/FRN/B4FF/LNABY46R/FRNB4FFLNABY46R.png&filename=Color-Mixing-Subtractive-Additive.png)
![Color-Mixing-Subtractive-Additive.png](/proxy/?url=https://content.instructables.com/FZX/LQIF/LNABY48W/FZXLQIFLNABY48W.png&filename=Color-Mixing-Subtractive-Additive.png)
-connect - to gnd
-connect B to gp 4
-connect G to gp 3
-connect R to gp 2
Source Code
![Color-Mixing-Subtractive-Additive.png](/proxy/?url=https://content.instructables.com/FUE/JZA1/LNABY4CO/FUEJZA1LNABY4CO.png&filename=Color-Mixing-Subtractive-Additive.png)
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
![png-transparent-colorful-fashion-banner-design-background-poster-banner-literature-and-art-small-fresh.png](/proxy/?url=https://content.instructables.com/F1C/KN4L/LNABY4KZ/F1CKN4LLNABY4KZ.png&filename=png-transparent-colorful-fashion-banner-design-background-poster-banner-literature-and-art-small-fresh.png)
you can use this handy HTML program to help you choose a colour