我正在做我自己的一个项目,该项目涉及树莓派上的伺服系统。我在执行代码时让它们旋转,但我更愿意让 python 脚本在 10 秒后自行终止,而不是一直按 CTRL + C。有没有办法用这个特定的代码做到这一点?
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
try:
while True:
GPIO.output(7,1)
time.sleep(0.0015)
GPIO.output(7,0)
time.sleep(0.01)
except KeyboardInterrupt:
print"Stopping Auto-Feeder"
GPIO.cleanup()