Step 1: RGB-Color LED light

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👇

2.RGB-LED传感器实验_bb.png

And here is the result👇

https://www.youtube.com/shorts/qhr2YFD2tG4

Step 2: 7-Color LED light

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👇

3.七彩LED灯闪烁_bb.png

And here is the result👇

https://www.youtube.com/shorts/XHTRG8qu_48

Step 3: Relay

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👇

4.继电器实验_bb.png

Here is the code I wrote👇