Skip to content

Instantly share code, notes, and snippets.

@professorjamesmoriarty
Created April 13, 2016 19:16
Show Gist options
  • Save professorjamesmoriarty/0c92df18da646b3292e9ef59ae95ffa8 to your computer and use it in GitHub Desktop.
Save professorjamesmoriarty/0c92df18da646b3292e9ef59ae95ffa8 to your computer and use it in GitHub Desktop.
import RPi.GPIO as GPIO
import time
import subprocess
from subprocess import call
import multiprocessing
GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, 1)
GPIO.setup(38, GPIO.OUT)
GPIO.output(38, 1)
GPIO.setup(37, GPIO.OUT)
GPIO.output(37, 1)
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]
LIGHTON = 0
MONITORON = 0
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)
def bootlights():
GPIO.output(37, 1)
GPIO.output(38, 1)
GPIO.output(40, 1)
GPIO.output(37, 0)
time.sleep(0.5)
GPIO.output(37, 1)
GPIO.output(40, 0)
time.sleep(0.5)
GPIO.output(38, 0)
GPIO.output(40, 1)
time.sleep(0.5)
GPIO.output(40, 0)
GPIO.output(38, 1)
time.sleep(0.5)
GPIO.output(40, 1)
GPIO.output(37, 0)
GPIO.output(38, 0)
time.sleep(0.5)
GPIO.output(40, 0)
time.sleep(0.5)
GPIO.output(38, 1)
time.sleep(0.5)
GPIO.output(37, 1)
GPIO.output(38, 0)
time.sleep(0.5)
GPIO.output(40, 0)
time.sleep(0.5)
GPIO.output(38, 0)
time.sleep(0.5)
GPIO.output(40, 1)
time.sleep(0.5)
GPIO.output(37, 1)
GPIO.output(38, 1)
GPIO.output(40, 1)
GPIO.output(40, 0)
time.sleep(0.5)
GPIO.output(40, 1)
GPIO.output(37, 0)
time.sleep(0.5)
GPIO.output(37, 1)
GPIO.output(38, 0)
time.sleep(0.2)
GPIO.output(38, 1)
time.sleep(0.5)
GPIO.output(38, 0)
time.sleep(0.5)
GPIO.output(38, 1)
time.sleep(0.3)
GPIO.output(38, 0)
time.sleep(0.5)
GPIO.output(38, 1)
time.sleep(0.3)
GPIO.output(38, 0)
time.sleep(2)
GPIO.output(38, 1)
bootlights()
def monitor(cmd):
p = subprocess.Popen([cmd], stdout=subprocess.PIPE)
out = p.communicate()
return out
try:
while (True):
time.sleep(0.25)
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
if ((KEYS[i][j]) == 1):
#do something
call(['xdotool', 'click', '3'])
if ((KEYS[i][j]) == 2):
#do something
call(["dmenu_run", "-nb", "#000000", "-nf", "#1bc210",
"-sb", "#0d5c08", "-sf", "#1bc210"])
if ((KEYS[i][j]) == 3):
#do something
pass
if ((KEYS[i][j]) == 4):
if (MONITORON == 0):
airmon = "sudo", "airmon-ng", "start", "wlan1"
mon = multiprocessing.Process(target=monitor(cmd=airmon))
mon.start()
MONITORON = 1
else:
call(["sudo", "killall", "airodump-ng"])
call(["sudo", "airmon-ng", "stop", "mon0"])
MONITORON = 0
if ((KEYS[i][j]) == 5):
if (LIGHTON == 1):
GPIO.output(37, 1)
GPIO.output(38, 1)
GPIO.output(40, 1)
LIGHTON = 0
else:
GPIO.output(37, 0)
GPIO.output(38, 0)
GPIO.output(40, 0)
LIGHTON = 1
if ((KEYS[i][j]) == 6):
GPIO.output(38, 0)
time.sleep(1)
GPIO.output(38, 1)
if ((KEYS[i][j]) == 7):
GPIO.output(37, 0)
time.sleep(1)
GPIO.output(37, 1)
if ((KEYS[i][j]) == 8):
#do something
pass
if ((KEYS[i][j]) == 9):
#do something
pass
if ((KEYS[i][j]) == 10):
#do something
pass
if ((KEYS[i][j]) == 11):
#do something
pass
if ((KEYS[i][j]) == 12):
#do something
pass
if ((KEYS[i][j]) == 13):
#do something
bootlights()
if ((KEYS[i][j]) == 14):
#do something
pass
if ((KEYS[i][j]) == 15):
#do something
pass
if ((KEYS[i][j]) == 16):
#do something
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