【发布时间】:2017-03-18 05:58:04
【问题描述】:
我正在开发自己的一个项目,该项目涉及树莓派上的伺服系统。我在执行代码时让它们旋转,但我更愿意让 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()
【问题讨论】:
-
检查是否过了10秒,然后退出循环。
标签: python linux time raspberry-pi servo