Created
April 5, 2015 12:51
-
-
Save serverwentdown/bc14941927f0f2b35364 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import * | |
import RPi.GPIO as GPIO | |
GPIO.setmode(GPIO.BOARD) # Use physical layout as reference pins | |
MATRIX = [[1, 2, 3, "A"], | |
[4, 5, 6, "B"], | |
[7, 8, 9, "C"], | |
["*", 0, "#", "D"]] | |
ROW = [13, 15, 19, 21] | |
COL = [12, 16, 18, 22] | |
GLED = 7 # Green LED | |
RLED = 11 # Red LED | |
# Setup LEDs | |
GPIO.setup(GLED, GPIO.OUT) | |
GPIO.setup(RLED, GPIO.OUT) | |
GPIO.output(GLED, False) | |
GPIO.output(RLED, False) | |
# Setup Matrix modes | |
for j in range(4): | |
GPIO.setup(COL[j], GPIO.OUT) | |
GPIO.output(COL[j], 1) | |
print(COL[j]) | |
for i in range(4): | |
GPIO.setup(ROW[i], GPIO.IN, pull_up_down = GPIO.PUD_UP) | |
print(ROW[i]) | |
inputpassword = "" | |
password = "2938" | |
try: | |
# Keep checking for keyboard events | |
while(True): | |
for j in range(4): | |
GPIO.output(COL[j], 0) | |
for i in range(4): | |
if GPIO.input(ROW[i]) is 0: | |
key = MATRIX[i][j] | |
print(MATRIX[i][j]) | |
if type(key) is int: | |
# Do stuff: | |
# Blink green LED once: | |
else: | |
if key is "D": | |
# Do stuff: | |
# Blink red LED once: | |
# When length is same as password's: | |
if (exp): | |
# Check for equality: | |
if (exp): | |
# Make green light solid for 10 seconds: | |
else: | |
# Make red light solid for 10 seconds: | |
# After that, clear inputpassword and reset lightså: | |
while GPIO.input(ROW[i]) is 0: | |
pass | |
GPIO.output(COL[j], 1) | |
except KeyboardInterrupt: | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment