Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # coding: utf-8
- import RPi.GPIO as gpio
- import time
- import mysql.connector
- from mysql.connector import Error
- #import threading
- #import thread
- #class keypad(threading.Thread):
- class keypad():
- matrix = [["1","2","3","A"],
- ["4","5","6","B"],
- ["7","8","9","C"],
- ["*","0","#","D"]]
- pins = []
- spalte = [32, 36, 38, 40]
- zeile = [12, 16, 18, 22]
- pin = ""
- zaehler = 0
- def __init__(self):
- #threading.Thread.__init__(self)
- gpio.setmode(gpio.BOARD)
- gpio.setwarnings(False)
- self.getCodes()
- print(self.pins)
- self.GpioSetup()
- def GpioSetup(self):
- for j in range(4):
- gpio.setup(self.spalte[j], gpio.OUT)
- gpio.output(self.spalte[j], 1)
- gpio.setup(self.zeile[j],gpio.IN, pull_up_down=gpio.PUD_UP)
- self.run()
- def keypad(self):
- while True:
- for j in range(4):
- gpio.output(self.spalte[j], 0)
- for i in range(4):
- if gpio.input(self.zeile[i]) == 0:
- benutzerEingabe = self.matrix[i][j]
- while gpio.input(self.zeile[i]) == 0:
- pass
- return benutzerEingabe
- gpio.output(self.spalte[j], 1)
- return False
- def run(self):
- try:
- while self.zaehler < 4:
- self.pin += self.keypad()
- print(self.pin)
- self.zaehler += 1
- time.sleep(0.2)
- except KeyboardInterrupt:
- gpio.cleanup()
- if self.zaehler == 4:
- if self.pin == self.pins[0] or self.pin == self.pins[1]:
- print("Access granted")
- else:
- print("Access denied")
- def getCodes(self):
- try:
- connection = mysql.connector.connect(host='localhost', database='zugang',user='root', password='abcD123')
- query = 'SELECT pin FROM rolle'
- cursor = connection.cursor()
- cursor.execute(query)
- records = cursor.fetchall()
- for row in records:
- self.pins.append(row[0])
- cursor.close()
- except Error as e:
- print("Error", e)
- finally:
- if(connection.is_connected()):
- connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement