-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLEDCode.py
More file actions
45 lines (39 loc) · 1.11 KB
/
LEDCode.py
File metadata and controls
45 lines (39 loc) · 1.11 KB
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
import RPi.GPIO as GPIO
import time
import os
img_counter = 0
SENSOR_PIN = 12
def setup():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(SENSOR_PIN, GPIO.IN)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
def handle_motion():
global img_counter
comand ="fswebcam -S 10 "
data = "image"+str(img_counter)+".jpg"
comand = comand + data
img_counter +=1
#print("%s",(comand))
os.system(comand)
def loop():
while True:
if GPIO.input(SENSOR_PIN) == 1:
GPIO.output(11,GPIO.HIGH)
GPIO.output(13,GPIO.LOW)
handle_motion()
time.sleep(1)
else:
GPIO.output(11,GPIO.LOW)
GPIO.output(13,GPIO.HIGH)
time.sleep(1)
def cleanup():
GPIO.cleanup()
GPIO.output(11,GPIO.LOW)
GPIO.output(13,GPIO.LOW)
if __name__ == "__main__":
setup()
try:
loop()
except KeyboardInterrupt:
cleanup()