Skip to content

Instantly share code, notes, and snippets.

@professorjamesmoriarty
Last active April 2, 2016 23:48
Show Gist options
  • Save professorjamesmoriarty/dd952029fdd7997c24d289acb221cd6d to your computer and use it in GitHub Desktop.
Save professorjamesmoriarty/dd952029fdd7997c24d289acb221cd6d to your computer and use it in GitHub Desktop.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
KEYS = [[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]]
COL = [15, 13, 11, 7]
ROW = [22, 16, 18, 12]
for j in range(4):
GPIO.setup(COL[j], GPIO.OUT)
GPIO.output(COL[j], 1)
for i in range(4):
GPIO.setup(ROW[i], GPIO.IN, pull_up_down=GPIO.PUD_UP)
try:
while(True):
time.sleep(0.2)
for j in range(4):
GPIO.output(COL[j], 0)
for i in range(4):
if GPIO.input(ROW[i]) == 0:
print(KEYS[i][j])
while(GPIO.input(ROW[i]) == 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