[英]Raspberry Pi 4 LED light blinking only blinks around 9 times, not continuously
I have used the below Python code for Raspberry Pi 4 to have LED light blink continuously but I only blinks for around 10 times and stops.我已经为 Raspberry Pi 4 使用了下面的 Python 代码让 LED 灯连续闪烁,但我只闪烁大约 10 次并停止。 I need it to blink continuously.我需要它不断闪烁。
import RPi.GPIO as GPIO
import time
redLED = 4
GPIO.setmode(GPIO.BCM)
GPIO.setup(redLED, GPIO.OUT)
try:
while True:
GPIO.output(redLED, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(redLED, GPIO.LOW)
time.sleep(0.5)
finally:
GPIO.cleanup()
You could try setting up the GPIO channel in every iteration.您可以尝试在每次迭代中设置 GPIO 通道。
import RPi.GPIO as GPIO
import time
redLED = 4
GPIO.setmode(GPIO.BCM)
try:
while True:
GPIO.setup(redLED, GPIO.OUT)
GPIO.output(redLED, True)
time.sleep(0.5)
GPIO.output(redLED, False)
time.sleep(0.5)
finally:
GPIO.cleanup()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.