0

i have a raspberry pi 3 (os:rasbian) and i want to run this code for exp at 13:00 when i leave the at home 12:00 but i want program will start 1 hour later. how can i modify the program. thanks

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()
glibdud
  • 7,550
  • 4
  • 27
  • 37
J.Pasha
  • 5
  • 1

1 Answers1

1

I would do it like this:

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()

This way, You can start program anytime You want and let it wait in the background. You activate it before You leave. You can also force it to start immediately if You need.

Fejs
  • 2,734
  • 3
  • 21
  • 40