This week, I continued to learn something about the accessories of Raspberry Pi. The first one I’ve studied is RGB-color LED light.
Here is the code I wrote👇
from gpiozero import RGBLED
from colorzero import Color
from time import sleep
colors = ['red', 'green', 'blue', 'yellow', 'magenta', 'cyan']
led = RGBLED(17, 18, 27)
# 调用循环函数
def makerobo_loop():
while True:
for col in colors:
led.color = Color(col)
sleep(0.5)
# 释放资源
def makerobo_destroy():
led.close()
# 程序入口
if __name__ == "__main__":
try:
makerobo_loop() # 调用循环函数
except KeyboardInterrupt: # 当按下Ctrl+C时,将执行destroy()子程序。
makerobo_destroy() # 释放资源
And here is the wiring diagram👇
And here is the result👇
https://www.youtube.com/shorts/qhr2YFD2tG4
Then I started to use the 7-color LED light to connect with the Raspberry Pi and because there is a chip in this light there is no code we need to write to light it up.
And here is the wiring diagram👇
And here is the result👇
https://www.youtube.com/shorts/XHTRG8qu_48
As we all know a relay is a tool to use low voltage to control high voltage, in this step, I use a relay to connect with Raspberry Pi to control a Two Color LED Light.
And here is the wiring diagram👇
Here is the code I wrote👇