Python 树莓皮发光二极管不闪烁
我试图让led每秒闪烁一次。这是我的代码:Python 树莓皮发光二极管不闪烁,python,raspberry-pi,Python,Raspberry Pi,我试图让led每秒闪烁一次。这是我的代码: import RPi.GPIO as gpio try: while True: gpio.output(20, 1) time.sleep(1) gpio.output(20, 0) except KeyboardInterrupt: gpio.cleanup() 问题是,我的LED指示灯刚刚亮起,而且不闪烁。执行gpio.output20,0后,您不会入睡。因此,当它重复wh
import RPi.GPIO as gpio
try:
while True:
gpio.output(20, 1)
time.sleep(1)
gpio.output(20, 0)
except KeyboardInterrupt:
gpio.cleanup()
问题是,我的LED指示灯刚刚亮起,而且不闪烁。执行gpio.output20,0后,您不会入睡。因此,当它重复while循环时,它会立即打开。这样做:
while True:
gpio.output(20, 1)
time.sleep(1)
gpio.output(20, 0)
time.sleep(1)