-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeypad_demo.py
59 lines (56 loc) · 1.55 KB
/
keypad_demo.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 doorControl
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
def checkkeypad(length):
MATRIX = [[1,2,3,'A'],
[4,5,6,'B'],
[7,8,9,'C'],
['*',0,'#','D']]
ROW = [7,11,13,15]
COL = [12,16,18,22]
result = []
# COL set HIGH
for j in range(4):
GPIO.setup(COL[j],GPIO.OUT)
GPIO.output(COL[j],1)
# ROW set HIGH
for i in range(4):
GPIO.setup(ROW[i], GPIO.IN, pull_up_down = GPIO.PUD_UP)
while(True):
for j in range(4):
# set COL LOW
GPIO.output(COL[j],0)
# Check inputs
for i in range(4):
if GPIO.input(ROW[i]) == 0:
print(MATRIX[i][j])
result.append(MATRIX[i][j])
while(GPIO.input(ROW[i]) == 0):
time.sleep(0.5)
GPIO.output(COL[j], 1)
if len(result) >= length:
return result
def checkpassword():
doorControl.door().lock()
password = [1,2,3,'A']
length = len(password)
print("Please enter password:")
result = checkkeypad(length)
if result == password:
doorControl.door().unlock()
print("Door Unlocked")
time.sleep(10)
doorControl.door().lock()
print("Door ReLocked")
else:
doorControl.door().lock()
print("Password failed")
try:
while(True):
checkpassword()
except KeyboardInterrupt:
doorControl.door().unlock()
doorControl.door().shutdown()
GPIO.cleanup()