-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathled_matrix.py
125 lines (112 loc) · 3.08 KB
/
led_matrix.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import max7219
import time
from machine import Pin, SPI
from framebuf import MONO_HLSB, MONO_HMSB, MONO_VLSB
def display_str(display, text):
for c in range(0, len(text)):
display.text(text[c], 0, 0, 1)
display.show()
time.sleep(0.3)
display.text(text[c], 0, 0, 0)
display.show()
time.sleep(0.05)
GLYPHS = {
"X": [
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 1, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 1, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
],
"a": [
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 0, 0, 1, 1, 0],
[0, 1, 1, 0, 0, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 1, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
],
"b": [
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 0, 0, 1, 1, 0],
[0, 1, 1, 0, 0, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
],
"c": [
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 0, 0, 1, 1, 0],
[0, 1, 1, 0, 0, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 1, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
],
}
spi = SPI(0, baudrate=10000000, polarity=1, phase=0, sck=Pin(2), mosi=Pin(3))
ss = Pin(5, Pin.OUT)
display = max7219.Matrix8x8(spi, ss, 1)
display.brightness(1)
display.fill(0)
# Test all pixels light up
for x in range(0, 8):
for y in range(0, 8):
display.pixel(x, y, 1)
display.show()
time.sleep(0.01)
for x in range(0, 8):
for y in range(0, 8):
display.pixel(x, y, 0)
display.show()
time.sleep(0.01)
#Test Text
text = "Hello World!"
display_str(display, text)
#Test Custom Glyphs
display.text_from_glyph("X", GLYPHS)
display.show()
display.fill(0)
time.sleep(0.5)
animation = "abccba"
for i in range(0, len(animation)):
display.fill(0)
display.text_from_glyph(animation[i], GLYPHS)
display.show()
time.sleep(0.25)
#Test Different Mapping Options
display = max7219.Matrix8x8(spi, ss, 1, MONO_VLSB)
display.fill(0)
display.text("P")
display.show()
time.sleep(0.5)
display = max7219.Matrix8x8(spi, ss, 1, MONO_HMSB)
display.fill(0)
display.text("P")
display.show()
time.sleep(0.5)
display = max7219.Matrix8x8(spi, ss, 1, MONO_HLSB)
display.fill(0)
display.text("P")
display.show()
time.sleep(0.5)
#Rotate GLYPHS
tmp_glyph = GLYPHS
display = max7219.Matrix8x8(spi, ss, 1)
display.fill(0)
display.text_from_glyph("a", tmp_glyph)
display.show()
time.sleep(0.25)
for i in range(0,8):
tmp_glyph.update({"a":list(zip(*tmp_glyph["a"][::-1]))})
display.text_from_glyph("a", tmp_glyph)
display.show()
time.sleep(0.25)