我有一个 Raspberry PI,我正在尝试让 LED 闪烁,如下所示:
def flash():
GPIO.output(channel, not GPIO.input(channel))
sleep(1)
GPIO.output(channel, not GPIO.input(channel))
如果我在代码中调用它,它就会闪烁一秒钟。
如果我循环使用它,使其闪烁 > 1 次,它不起作用。
while True:
flash()
它从不闪烁。如果我在循环外连续调用 flash 2 次,它就会起作用。
什么给出了?
最佳答案
关闭后看到闪烁的 LED 不应该休眠吗?
尝试删除第二个 GPIO.output(channel, not GPIO.input(channel))
调用,然后尝试使用 while 循环。
def flash():
GPIO.output(channel, not GPIO.input(channel))
sleep(1)
while True:
flash()
关于python - Raspberry PI for 循环使 LED 闪烁不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27728245/