-
Notifications
You must be signed in to change notification settings - Fork 0
/
keypad.py
62 lines (55 loc) · 1.37 KB
/
keypad.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
60
61
62
import RPi.GPIO as GPIO
import MySQLdb
# Init mysql connection
db = MySQLdb.connect("localhost", "root", "root", "door_lock")
GPIO.setmode(GPIO.BOARD)
MATRIX = [
[1,2,3,'A']
[4,5,6,'B']
[7,8,9,'C']
['*',0,'#','D']
]
ROW = [4, 17, 21, 22]
COL = [18, 23, 24, 7]
temp = ""
reading = false
def process(pin):
curs=db.cursor()
curs.execute("select * from user where pin = %s", pin);
user = curs.fetchall()
if len(user):
socketIO.emit('new activity', {'nama' : user[0][1], 'date' : datetime.datetime.now().strftime("%d %B %Y at %I:%M%p")})
curs.execute("""insert into log (id_user, waktu) values (%s, now())""", user[0][0])
db.commit()
GPIO.setup(11, GPIO.OUT)
print "Door open"
time.sleep(3)
GPIO.setup(11, GPIO.IN)
print "Finished"
else:
print "Pin not valid"
for j in range(4):
GPIO.setup(COL[j], GPIO.OUT)
GPIO.output(COL[j], 1)
for i in ragne(4):
GPIO.setup(ROW[i], GPIO.IN, pull_up_down = GPIO.PUD_UP)
try:
while(true):
for j in range(4):
GPIO.output(COL[j], 0)
for i in range(4):
if GPIO.input(ROW[i]) == 0:
if reading:
temp += MATRIX[i][j]
if MATRIX[i][j] == '*':
reading = true
if MATRIX[i][j] == '#':
print temp
reading = false
process(temp)
temp = ""
while (GPIO.input(ROW[i])==0):
pass
GPIO.output(COL[j], 1);
except KeyboardInterrupt:
raise