这是我的raspberry-pi的RGB闪烁代码细节
蓝色和绿色闪烁,但红色不起作用,我也尝试更换gpio引脚,但结果相同
import RPi.GPIO as GPIO
red_pin = 18
green_pin = 23
blue_pin = 24
GPIO.setmode(GPIO.BOARD)
GPIO.setup(red_pin, GPIO.OUT)
GPIO.setup(green_pin, GPIO.OUT)
GPIO.setup(blue_pin, GPIO.OUT)
GPIO.setwarnings(False)
GPIO.output(red_pin, False)
GPIO.output(green_pin, False)
GPIO.output(blue_pin, False)
try:
while True:
UserInput = input()
UserInput = str(User)
if UserInput == "red":
GPIO.output(red_pin, True)
GPIO.output(green_pin, False)
GPIO.output(blue_pin, False)
elif UserInput == "green":
GPIO.output(red_pin, False)
GPIO.output(green_pin, True)
GPIO.output(blue_pin, False)
elif UserInput == "blue":
GPIO.output(red_pin, False)
GPIO.output(green_pin, False)
GPIO.output(blue_pin, True)
else:
print("Only red, green, and blue are valid colors.")
finally:
print("Cleaning up.")
GPIO.cleanup()
答案 0 :(得分:0)
实际上,解决方案非常简单。尝试使用另一个拥有的LED,它似乎可以正常工作。
您在使用电阻器吗? 因为我所能收集到的是您设法吹起了RGB LED的红色部分。