-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main_cam.py
59 lines (42 loc) · 1.29 KB
/
Main_cam.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import RPi.GPIO as GPIO
import time
import asyncio
from picamera import PiCamera
from gpiozero import MotionSensor
import random
# Definitions
IRSens = 14 #number of the pin connected to the sensor
Camera = PiCamera()
# GPIO setup
GPIO.setmode(GPIO.BCM) # naming convention links number to the pin
GPIO.setup(IRSens, GPIO.IN)
# Camera activate by IR motion sensor
try:
print("Sensor Running - press CTRL + C to quit...")
time.sleep(2)
print("Ready")
while True:
if GPIO.input(IRSens):
print("Motion Detected!")
time.sleep(2)
Camera.start_preview()
Camera.stop_preview()
Camera.start_recording('/home/pi/Desktop/t.h264')
print("Recording Commenced...")
time.sleep(15)
Camera.stop_recording()
print("Recording Complete!")
time.sleep(0.5)
time.sleep(0.1)
except KeyboardInterrupt:
print("Quit")
GPIO.cleanup()
# while True:
# while 1:
# if GPIO.input(IRSens):
# print("Recording")
# Camera.start_recording('/home/pi/Desktop/t' + str(random.randint(0,100)) +'.h264')
# time.sleep(20)
# else:
# print("No Motion")
# time.sleep(5)