Page MenuHomec4science

demo.py
No OneTemporary

File Metadata

Created
Mon, May 20, 11:51
#!/usr/bin/env python2
import serial
import time
DEBUG = 1
SERIAL = 1
PORT = '/dev/ttyS1'
SPEED = 9600
LEDS_NUMBER = 8
LEDS_MAX = 100
TIME = 0.1
def debug(msg):
if DEBUG:
f = open('/tmp/debug_demo', 'a+')
f.write(str(msg) + "\n")
f.close()
def write(line):
if SERIAL:
ser.write(line)
debug(line)
def kitt(ser):
for i in [0, 1, 2, 3, 2, 1]:
for j in xrange(4):
line = 'l%d ' % j + '%d 0 0 ' % (LEDS_MAX if i==j else 0) * LEDS_NUMBER
write(line)
time.sleep(TIME)
def colors():
step = 32
for r in xrange(0, LEDS_MAX, step):
for g in xrange(0, LEDS_MAX, step):
for b in xrange(0, LEDS_MAX, step):
for index in xrange(4):
line = 'l%d ' % index + '%d %d %d ' % (r, g, b) * LEDS_NUMBER
write(line)
time.sleep(TIME)
def text():
letters = {
'1E': [[0,1,0,0,0,1,0,0],[0,1,0,1,0,1,0,0],[0,1,0,1,0,1,0,0],[0,1,1,1,1,1,0,0]],
'2P': [[0,1,1,1,0,0,0,0],[0,1,0,1,0,0,0,0],[0,1,0,1,0,0,0,0],[0,1,1,1,1,1,0,0]],
'3F': [[0,1,0,0,0,0,0,0],[0,1,0,1,0,0,0,0],[0,1,0,1,0,0,0,0],[0,1,1,1,1,1,0,0]],
'4L': [[0,0,0,0,0,1,0,0],[0,0,0,0,0,1,0,0],[0,0,0,0,0,1,0,0],[0,1,1,1,1,1,0,0]],
#'S': [[0,1,0,1,1,1,0,0],[0,1,0,1,0,1,0,0],[0,1,0,1,0,1,0,0],[0,1,1,1,0,1,0,0]],
#'C': [[0,1,1,1,1,1,0,0],[0,1,0,0,0,1,0,0],[0,1,0,0,0,1,0,0],[0,1,1,1,1,1,0,0]],
#'I': [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,1,1,1,1,1,0,0],[0,0,0,0,0,0,0,0]],
#'T': [[0,0,0,0,0,0,0,0],[0,1,0,0,0,0,0,0],[0,1,1,1,1,1,0,0],[0,1,0,0,0,0,0,0]],
#'A': [[0,1,1,1,1,1,0,0],[0,1,0,1,0,0,0,0],[0,1,0,1,0,0,0,0],[0,1,1,1,1,1,0,0]],
#'S': [[0,1,0,1,1,1,0,0],[0,1,0,1,0,1,0,0],[0,1,0,1,0,1,0,0],[0,1,1,1,0,1,0,0]],
'5_': [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]],
}
for l in letters.keys():
index = 0
for r in letters[l]:
line = 'l%d ' % index \
+ ' '.join([str(x).replace("1", str(LEDS_MAX)) + ' 0 0 '
for x in r])
write(line)
time.sleep(0.06)
index += 1
time.sleep(0.6)
ser = None
if SERIAL:
ser = serial.Serial(PORT, SPEED)
try:
while True:
text()
#colors()
#kitt()
except KeyboardInterrupt:
if SERIAL:
ser.close()

Event Timeline