-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtextdot.py
87 lines (64 loc) · 1.75 KB
/
textdot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import time
import serial
import fiveBySevenFont
# Init startbits and endbits for matrix
startbit1 = [0x80, 0x85, 0x01]
startbit2 = [0x80, 0x85, 0x02]
endbit = 0x8F
# Init Serial port
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate=57600,
timeout=1,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
# Clear board subroutine
def clearBoard():
for x in startbit1:
ser.write(chr(x))
for x in range(0, 28):
ser.write(chr(0x00))
ser.write(chr(endbit))
for x in startbit2:
ser.write(chr(x))
for x in range(0, 28):
ser.write(chr(0x00))
ser.write(chr(endbit))
# Define string to scroll - this can be any length really. Begin with five blank spaces to create illusion of wrapping
outstr = " Welcome"
# Init list for holding chars to matrix
outlist = []
# Start with clearing the matrix
clearBoard()
# Loop through characters in message string
for x in outstr:
# Get binary string from fiveBySeven-font
thisbin = fiveBySevenFont.getBinaryFromChar(x)
for y in thisbin:
# Add char number to outlist
outlist.append(int(y, 2))
outlist.append(0)
framecount = 0
while (1 == 1):
# Loop through 28 cols of matrix
for x in range(0, 28):
if (framecount > len(outlist)): framecount = 0
framelist = outlist[framecount:] # Get 28 chars from outlist, starting with current frame
# Write starting bits
for z in startbit1:
ser.write(chr(z))
# Write to first unit
for y in framelist:
ser.write(chr(y))
ser.write(chr(endbit))
for z in startbit2:
ser.write(chr(z))
# Write silly binary animation to second unit, just because. :)
for p in range(0, 28):
ser.write(chr(x))
ser.write(chr(endbit))
# Wait to give matrix time to update, then count up
time.sleep(0.1)
framecount+= 1