from machine import Pin, PWM
import utime
class RGBLED:
def __init__(self, red_pin, green_pin, blue_pin, anode_common=False):
self.red = PWM(Pin(red_pin), freq=200, invert=anode_common)
self.green = PWM(Pin(green_pin), freq=200, invert=anode_common)
self.blue = PWM(Pin(blue_pin), freq=200, invert=anode_common)
self.anode_common = anode_common
def pwm(self, r, g, b):
r = int(r * 65535 / 255)
g = int(g * 65535 / 255)
b = int(b * 65535 / 255)
self.red.duty_u16(r)
self.green.duty_u16(g)
self.blue.duty_u16(b)
a_led = RGBLED(28, 27, 26, anode_common=True) #アノードコモン
c_led = RGBLED(3, 2, 1) #カソードコモン
Illumination = [
(64, 154, 227),
(128, 0, 128),
(50, 150, 50),
(255, 30, 30),
(0, 128, 255),
(99, 199, 0),
(128, 128, 128),
(255, 100, 0)
]
while True:
for r, g, b in Illumination:
a_led.pwm(r, g, b)
c_led.pwm(r, g, b)
utime.sleep(1)