Skip to content

Instantly share code, notes, and snippets.

@505e06b2
Created August 5, 2022 19:17
Show Gist options
  • Save 505e06b2/ecd384170360755470b397bd81dfef3a to your computer and use it in GitHub Desktop.
Save 505e06b2/ecd384170360755470b397bd81dfef3a to your computer and use it in GitHub Desktop.
Launchpad Clock (for Novation Launchpad Mini)
#!/usr/bin/env python2
import launchpad_rtmidi_py as launchpad
import time
lp = launchpad.Launchpad()
if not lp.Open():
print("Failed...\nReconnect...")
quadrants = [
{"x": 0, "y": 0, "colour": 0x11},
{"x": 4, "y": 0, "colour": 0x10},
]
hours = [202,203,204,205,206,207,8,24,40,56,72,88] # 0 will never be on?
digits = [
[ # 0
0,1,1,0,
1,0,0,1,
1,0,0,1,
1,0,0,1,
1,0,0,1,
1,0,0,1,
1,0,0,1,
0,1,1,0,
],
[ # 1
0,0,1,0,
0,1,1,0,
1,0,1,0,
0,0,1,0,
0,0,1,0,
0,0,1,0,
0,0,1,0,
1,1,1,1,
],
[ # 2
0,1,1,0,
1,0,0,1,
0,0,0,1,
0,0,0,1,
0,0,1,0,
0,1,0,0,
1,0,0,0,
1,1,1,1,
],
[ # 3
0,1,1,0,
1,0,0,1,
0,0,0,1,
0,0,0,1,
0,1,1,1,
0,0,0,1,
1,0,0,1,
0,1,1,0,
],
[ # 4
1,0,0,0,
1,0,0,1,
1,0,0,1,
1,0,0,1,
0,1,1,1,
0,0,0,1,
0,0,0,1,
0,0,0,1,
],
[ # 5
1,1,1,1,
1,0,0,0,
1,0,0,0,
1,0,0,0,
1,1,1,0,
0,0,0,1,
1,0,0,1,
0,1,1,0,
],
[ # 6
0,1,1,0,
1,0,0,1,
1,0,0,0,
1,0,0,0,
1,1,1,0,
1,0,0,1,
1,0,0,1,
0,1,1,0,
],
[ # 7
1,1,1,1,
0,0,0,1,
0,0,0,1,
0,0,1,0,
0,0,1,0,
0,1,0,0,
0,1,0,0,
0,1,0,0,
],
[ # 8
0,1,1,0,
1,0,0,1,
1,0,0,1,
1,0,0,1,
0,1,1,0,
1,0,0,1,
1,0,0,1,
0,1,1,0,
],
[ # 9
0,1,1,0,
1,0,0,1,
1,0,0,1,
1,0,0,1,
0,1,1,1,
0,0,0,1,
1,0,0,1,
0,1,1,0,
],
]
m = [0] * 64
def placenum(quadrant, digit):
global m
q = quadrants[quadrant]
d = digits[int(digit)]
y = q["y"]
x = q["x"]
for z in range(len(d)):
y = q["y"] + z/4
x = q["x"] + z%4
m[x + y*8] = d[z] * q["colour"]
#print d[z]
try:
seconds = False
reset_hour_lights = False
while True:
strings = time.strftime("%I:%M").split(':')
placenum(0, strings[1][0])
placenum(1, strings[1][1])
x = 0
i = 0
while x < 120:
lp.LedCtrlRaw(x,
m[i] & 0xF0,
m[i] & 0x0F
)
x += 1
i += 1
if x % 8 == 0:
x += 8
if strings[0] == "01" and reset_hour_lights: #only clear lights when hour is smaller than before
for x in hours:
lp.LedCtrlRaw(x, 0,0)
reset_hour_lights = False
elif strings[0] == "00" or strings[0] == "12":
strings[0] = "12"
reset_hour_lights = True
orange = False
for x in range(int(strings[0])):
lp.LedCtrlRaw(hours[x], int(orange),1)
orange = not orange
if seconds:
lp.LedCtrlRaw(200, 1,0)
lp.LedCtrlRaw(201, 0,0)
lp.LedCtrlRaw(104, 0,0)
lp.LedCtrlRaw(120, 1,0)
else:
lp.LedCtrlRaw(200, 0,0)
lp.LedCtrlRaw(201, 1,0)
lp.LedCtrlRaw(104, 1,0)
lp.LedCtrlRaw(120, 0,0)
seconds = not seconds
time.sleep(1)
lp.ButtonFlush()
except KeyboardInterrupt:
lp.Reset()
lp.Close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment