我有一个树莓派3(os:rasbian),我想在13:00离开家12:00时在exp的13:00运行此代码,但我希望程序将在1小时后启动。我该如何修改程序。谢谢
import time
import picamera
with picamera.PiCamera() as camera:
camera.start_preview()
try:
for i, filename in enumerate(camera.capture_continuous('/home/pi/Google Drive/{timestamp:%H-%M-%S}-{counter:03d}.jpg')):
print(filename)
time.sleep(3)
if i == 3:
break
finally:
camera.stop_preview()
我会这样:
import time
import picamera
# Pause program until Enter is pressed (press when You leave the home)
start = raw_input('Press Enter to start the counter: ') # or input(), if You use Python3
# Show message
print('Camera will start recording in 1 hour')
# Capture Ctrl-C
try:
# Sleep for an hour
time.sleep(3600)
# Maybe You want to start immediately, pressed Ctrl-C
except KeyboardInterrupt:
print('Starting camera now')
with picamera.PiCamera() as camera:
camera.start_preview()
try:
for i, filename in enumerate(camera.capture_continuous('/home/pi/Google Drive/{timestamp:%H-%M-%S}-{counter:03d}.jpg')):
print(filename)
time.sleep(3)
if i == 3:
break
finally:
camera.stop_preview()
这样,您可以随时启动程序,并使其在后台等待。您在离开之前将其激活。如果需要,您也可以强制其立即启动。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句