Created
December 6, 2015 13:43
-
-
Save ranbogmord/d0e91b1b725dc2a7675e to your computer and use it in GitHub Desktop.
Read Launchpad Mini signals
This file contains 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
import os | |
from subprocess import * | |
import re | |
proc = Popen('amidi -p hw:1 --dump', shell=True, stdout=PIPE) | |
def create_grid(size): | |
grid = [] | |
for i in range(0, size): | |
newarr = [] | |
for j in range(0, size): | |
newarr.append(0) | |
grid.append(newarr) | |
return grid | |
grid = create_grid(9) | |
def show_grid(): | |
for i in range(0, len(grid)): | |
row = "|" | |
for j in range(0, len(grid[i])): | |
row += str(grid[i][j]) + "|" | |
print row | |
show_grid() | |
regex = "([A-Z0-9]+)\s?([A-Z0-9])([A-Z0-9])\s?([A-Z0-9]+)" | |
tester = re.compile(regex) | |
while True: | |
data = proc.stdout.readline() | |
if len(data) > 0: | |
print data | |
if tester.match(data): | |
matches = re.search(regex, data) | |
t = matches.group(1) | |
if t == "90": | |
row = int(matches.group(2)) | |
col = int(matches.group(3)) | |
act = matches.group(4) | |
if act == "7F": | |
act = 1 | |
else: | |
act = 0 | |
grid[row][col] = act | |
os.system('clear') | |
show_grid() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment