【发布时间】:2019-06-27 13:49:34
【问题描述】:
这是我的 raspberry-pi RGB 闪烁的代码详细信息
蓝色和绿色闪烁但红色不工作我也尝试交换gpio pin但我得到相同的结果
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()
【问题讨论】:
-
您有其他可以尝试的红色 LED 灯吗?也许是为了确保它也不是被破坏的 LED 本身