一、树莓派默认用户名与密码:
用户名:pi
密码:raspberry
二、树莓派3引脚图:
四、树莓派实现RGB LED的颜色控制
R,G,B 分别对应 GPIO15,GPIO18,GPIO14,GND对应GPIO13
import RPi.GPIO as rg
import time
R,G,B=15,18,14
rg.setmode(rg.BCM)
rg.setup(R,rg.OUT)
rg.setup(G,rg.OUT)
rg.setup(B,rg.OUT)
pwmR=rg.PWM(R,70)
pwmG=rg.PWM(G,70)
pwmB=rg.PWM(B,70)
pwmR.start(0)
pwmG.start(0)
pwmB.start(0)
try:
t=0.4
while True:
# 红色灯全亮,蓝灯,绿灯全暗(红色)
pwmR.ChangeDutyCycle(0)#e
pwmG.ChangeDutyCycle(100)
pwmB.ChangeDutyCycle(100)
time.sleep(t)
# 绿色灯全亮,红灯,蓝灯全暗(绿色)
pwmR.ChangeDutyCycle(100)
pwmG.ChangeDutyCycle(0)
pwmB.ChangeDutyCycle(100)
time.sleep(t)
# 蓝色灯全亮,红灯,绿灯全暗(蓝色)
pwmR.ChangeDutyCycle(100)
pwmG.ChangeDutyCycle(100)
pwmB.ChangeDutyCycle(0)
time.sleep(t)
# 红灯,绿灯全亮,蓝灯全暗(黄色)
pwmR.ChangeDutyCycle(0)
pwmG.ChangeDutyCycle(0)
pwmB.ChangeDutyCycle(100)
time.sleep(t)
# 红灯,蓝灯全亮,绿灯全暗(洋红色)
pwmR.ChangeDutyCycle(0)
pwmG.ChangeDutyCycle(100)
pwmB.ChangeDutyCycle(0)
time.sleep(t)
# 绿灯,蓝灯全亮,红灯全暗(青色)
pwmR.ChangeDutyCycle(100)
pwmG.ChangeDutyCycle(0)
pwmB.ChangeDutyCycle(0)
time.sleep(t)
# 红灯,绿灯,蓝灯全亮(白色)
pwmR.ChangeDutyCycle(0)
pwmG.ChangeDutyCycle(0)
pwmB.ChangeDutyCycle(0)
time.sleep(t)
# 调整红绿蓝LED的各个颜色的亮度组合出各种颜色
for r in range (0, 101, 20):
pwmR.ChangeDutyCycle(r)
for g in range (0, 101, 20):
pwmG.ChangeDutyCycle(g)
for b in range (0, 101, 20):
pwmB.ChangeDutyCycle(b)
time.sleep(0.01)
except KeyboardInterrupt:
pass
pwmR.stop()
pwmG.stop()
pwmB.stop()
rg.cleanup()
time.sleep(t)