from machine import Pin,PWM
from time import sleep
# colors that we are going to display
colors = {
"pink": (255, 0, 255),
"yellow": (255,255,0),
"skyblue": (0, 255, 255),
"orange": (230, 138 , 0),
"white": (255, 255 , 255)
}
def map_range(x, in_min, in_max, out_min, out_max):
return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min
# LED connect in a common-cathode design
rgb1_r = PWM(Pin(12,Pin.OUT))
rgb1_g = PWM(Pin(13,Pin.OUT))
rgb1_b = PWM(Pin(14,Pin.OUT))
# LED connect in a common-anode design
rgb2_r = PWM(Pin(15,Pin.OUT))
rgb2_g = PWM(Pin(16,Pin.OUT))
rgb2_b = PWM(Pin(17,Pin.OUT))
while True:
for key, color in colors.items():
# reset each RGB
rgb1_r.duty_u16(0)
rgb1_g.duty_u16(0)
rgb1_b.duty_u16(0)
rgb2_r.duty_u16(0)
rgb2_g.duty_u16(0)
rgb2_b.duty_u16(0)
# color to display
red, green, blue = color
rgb1_r.duty_u16(map_range(red, 0, 255, 0, 65535))
rgb1_g.duty_u16(map_range(green, 0, 255, 0, 65535))
rgb1_b.duty_u16(map_range(blue, 0, 255, 0, 65535))
rgb2_r.duty_u16(map_range(red, 0, 255, 0, 65535))
rgb2_g.duty_u16(map_range(green, 0, 255, 0, 65535))
rgb2_b.duty_u16(map_range(blue, 0, 255, 0, 65535))
sleep(1)