I am building an motion detection security camera with a raspberry pi https://www.raspberrypi.org/learning/parent-detector/worksheet/.
The code works fine, but I want the device to run my python code at startup and I want it to close the program when I hit a certain key. As of now, the program runs but wont get out of the loop so I can't get to the raspberry pi desktop (my workaround to this is turning the device off, manually removing the camera, turn the device back on, to get an error because camera is not detected which exits the code to the desktop....very inefficient I know!)
Essentially, this code was written to run the program from a pi that is connected to a monitor, keyboard, etc. I want to just plug it in somewhere and have it arm the camera. Then after I return to the house (work, vacation, etc), I want to plug in a keyboard, hit a key to exit the program, shutdown safly and be able to view any security incidents when I connect it to a monitor.
script code:
from gpiozero import MotionSensor
from picamera import PiCamera
from datetime import datetime
camera = PiCamera()
pir = MotionSensor(4)
while True:
pir.wait_for_motion()
filename = datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264")
camera.start_recording(filename)
pir.wait_for_no_motion()
camera.stop_recording()