-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
34 lines (26 loc) · 771 Bytes
/
main.py
File metadata and controls
34 lines (26 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
Runs raspistill as subprocess, button press sends keyboard 'Enter' to trigger camera.
"""
import os
import signal
import subprocess
import time
import gpiozero
def main():
raspistill_proc = subprocess.Popen(
["raspistill -t 0 -k -dt -fli 60hz -o /home/pi/Pictures/image%d.jpg"],
stdin=subprocess.PIPE, shell=True)
button = gpiozero.Button(21)
def capture_image():
print("got trigger")
raspistill_proc.stdin.write("\n")
button.when_pressed = capture_image
print("program is running")
try:
while True:
button.wait_for_press()
finally:
print("killing process")
os.killpg(os.getpgid(raspistill_proc.pid), signal.SIGTERM)
if __name__ == "__main__":
main()