-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlock_and_sensor.py
53 lines (48 loc) · 1.09 KB
/
lock_and_sensor.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
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import sys
import os
import re
GPIO.setmode(GPIO.BCM)
GPIO.setup(15, GPIO.IN, pull_up_down = GPIO.PUD_UP)
pinList = [26, 20, 21]
flag = 0
keywords=['Matthew','Fadi']
with open('match.txt') as f:
txt=f.read()
## for profile in keywords:
for profile in keywords:
if re.search(r'\b{}\b'.format(profile),txt):
flag = 1
if flag:
print("MATCH")
print("GREEN")
print ("OPEN")
for i in pinList:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.HIGH)
else:
print("NO MATCH")
print("RED")
for i in pinList:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.LOW)
try:
GPIO.output(26, GPIO.LOW)
# time.sleep(5);
while True:
if GPIO.input(15):
print ("--DOOR SENSOR OPEN--")
time.sleep(2)
else:
print ("--DOOR SENSOR CLOSED--")
#break
time.sleep(2)
GPIO.cleanup()
print ("Close")
# End program cleanly with keyboard
except KeyboardInterrupt:
print (" Quit")
# Reset GPIO settings
GPIO.cleanup()