Step 1: Double-Color LED light

This week, I will start learning how to use a Raspberry Pi to connect sensors. The first thing I do is connect the Double-Color LED light.

here is my code👇

from gpiozero import PWMLED
from time import sleep

colors = [0xFF00, 0x00FF, 0x0FF0, 0xF00F]
makerobo_pins = (17, 18)  # PIN管脚字典,红色LED接GPIO17,绿色LED接GPIO18

p_R = PWMLED(pin=makerobo_pins[0],initial_value = 0, frequency=2000)  # 设置频率为2KHz
p_G = PWMLED(pin=makerobo_pins[1],initial_value = 0, frequency=2000)  # 设置频率为2KHz

def makerobo_pwm_map(x, in_min, in_max, out_min, out_max):
	return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min

def makerobo_set_Color(col):   # 例如:col = 0x1122
	R_val = col  >> 8
	G_val = col & 0x00FF
	# 把0-255的范围同比例缩小到0-100之间
	R_val = makerobo_pwm_map(R_val, 0, 255, 0, 100)
	G_val = makerobo_pwm_map(G_val, 0, 255, 0, 100)
	
	p_R.value = (R_val)/100.0     # 改变占空比
	p_G.value = (G_val)/100.0     # 改变占空比

# 调用循环函数
def makerobo_loop():
	while True:
		for col in colors:
			makerobo_set_Color(col)
			sleep(0.5)
# 释放资源
def makerobo_destroy():
	p_G.close()
	p_R.close()

# 程序入口
if __name__ == "__main__":
	try:
		makerobo_loop()        # 调用循环函数
	except KeyboardInterrupt:  # 当按下Ctrl+C时,将执行destroy()子程序。
		makerobo_destroy()     # 释放资源

Below is the wiring diagram👇

1.双色LED灯实验_bb.png

I forgot to take the video so I can not put the result here.😂

Step 2: Learn something about Git and GitHub

On weekends, I learned something about Git to spend my leisure time, Git is a distributed version control system used for tracking changes in source code during software development.

This is how I use Git to manage my project👇

截屏2024-11-02 14.13.38.png

And also, I publish these codes on my GitHub, and here is my GitHub👇

https://github.com/JunxiBao