-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
83 lines (76 loc) · 2.31 KB
/
__init__.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
import bhi160
import display
import leds
import os
import utime
try:
accel = bhi160.BHI160Accelerometer()
except:
os.reset()
leds.clear()
with display.open() as d:
d.clear()
d.update()
for i in range(3):
leds.set_rocket(i, 0)
# Characters are encoded in columns per 11 bits in an integer.
# LSB = top, MSB = bottom.
charset = {
'A': [0x780, 0x178, 0x107, 0x178, 0x780],
'B': [0x7ff, 0x663, 0x663, 0x19c],
'C': [0x1fc, 0x306, 0x603, 0x603],
'D': [0x7ff, 0x603, 0x603, 0x30e, 0x1fc],
'E': [0x7ff, 0x663, 0x663, 0x663],
'F': [0x7ff, 0x063, 0x063, 0x063],
'G': [0x7ff, 0x603, 0x633, 0x1e6],
'H': [0x7ff, 0x060, 0x060, 0x7ff],
'I': [0x603, 0x7ff, 0x603],
'J': [0x780, 0x603, 0x603, 0x7ff],
'K': [0x7ff, 0x070, 0x1dc, 0x707],
'L': [0x7ff, 0x600, 0x600, 0x600],
'M': [0x7ff, 0x006, 0x0fc, 0x006, 0x7ff],
'N': [0x7ff, 0x00e, 0x078, 0x1c0, 0x7ff],
'O': [0x1fc, 0x603, 0x603, 0x603, 0x1fc],
'P': [0x7ff, 0x063, 0x03e, 0x01c],
'Q': [0x1fc, 0x603, 0x683, 0x703, 0x7fc],
'R': [0x7ff, 0x063, 0x3e3, 0x41c],
'S': [0x67f, 0x663, 0x663, 0x7e3],
'T': [0x003, 0x003, 0x7ff, 0x003, 0x003],
'U': [0x1ff, 0x600, 0x600, 0x600, 0x1ff],
'V': [0x00f, 0x0f0, 0x700, 0x0f0, 0x00f],
'W': [0x7ff, 0x300, 0x8f0, 0x300, 0x7ff],
'X': [0x603, 0x1dc, 0x020, 0x1dc, 0x603],
'Y': [0x003, 0x00c, 0x7f8, 0x00c, 0x003],
'Z': [0x783, 0x6c3, 0x673, 0x61b, 0x60f],
'_': [0x400] * 4,
}
nick = 'sample text'
try:
with open('/nickname.txt', 'r') as f:
nick = str(f.read())
except:
pass
string = []
for c in nick.upper():
if not c in charset:
c = '_'
string = string + charset[c] + [0]
while True:
sign = lambda v: 1 if v>=0 else -1
accel_hist = []
direction = 0
while direction == 0:
samples = accel.read()
accel_hist.extend([ 0 if abs(s.y) < 0.2 else s.y for s in samples ])
accel_hist = accel_hist[max(len(accel_hist)-20, 0):]
if len(accel_hist) > 2:
direction = sign(accel_hist[-1]) - sign(accel_hist[-2])
colors = [(0, 0, 0), (0xff, 0xff, 0xff)]
string_iter = string
if direction > 0:
string_iter = reversed(string_iter)
for column in string:
for l in range(11):
leds.set(10-l, colors[column>>l & 1])
leds.clear()
utime.sleep(0.001)