-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmulti_sensor
More file actions
36 lines (30 loc) · 965 Bytes
/
multi_sensor
File metadata and controls
36 lines (30 loc) · 965 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
35
36
import RPi.GPIO as GPIO
import picamera
import time
import datetime
def record(): #10초간 녹화해서 "날짜 시간.h264"로 저장하는 함수
camera = picamera.Picamera()
camera.resolution = (1280, 720)
now = datetime.datetime.now()
filename = now.strftime('%Y-%m-%d %H:%M:%S')
camera.start_recording(output = filename + '.h264')
camera.wait_recording(10)
camera.stop_recording()
def sense():
GPIOIN = 1
GPIOOUT = 2
GPIO.setmode(GPIO.BCM)
GPIO.setup(GPIOIN, GPIO.IN)
GPIO.setup(GPIOOUT, GPIO.OUT)
while True:
state = GPIO.input(GPIOIN) #움직임이 감지되었는지 여부를 받아
if (state == True): #움직임이 감지되면 녹화
startTime = time.time()
while True:
nowTime = time.time()
if (nowTime - startTime >= 10):
record()
break
GPIO.output(GPIOOUT, state)
time.sleep(0.5)
GPIO.cleanup()