forked from mcauser/micropython-max7219
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.py
More file actions
47 lines (41 loc) · 1.71 KB
/
Copy pathmatrix.py
File metadata and controls
47 lines (41 loc) · 1.71 KB
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
# This is a helper class to make working with LED matrixes easier
import max7219
from machine import Pin, SPI
from time import sleep
class Matrix:
def __init__(self, cspin = 15, sckpin = 14, mosipin = 13, num = 1):
spi = SPI(1, baudrate=14500000, sck = Pin(int(sckpin)), mosi = Pin(int(mosipin)))
self.display = max7219.Max7219(spi, Pin(int(cspin)), num)
self.display.brightness(0)
# Display normal text
def text(self, txt, x = 0, y = 0, c = 1):
self.display.fill(0)
self.display.text(txt, x, y, c)
self.display.show()
# Scrolling text. I was not able to make official scroll method work,
# also on the website they warn "This may leave a footprint of the previous colors in the FrameBuffer."
# So I wrote this simple method which speed is adjustable.
# For now, I'm waiting for my other led matrixes to arrive, then I can test further and add more options like scroll direction and etc.
def scroll(self, txt, s = 0.5, c = 1, loops = 0):
text_len = len(txt) * 8 + 8
counter = 1
while True:
for i in range(text_len):
self.text(txt, 8 - i)
sleep(s)
if loops != 0:
if counter >= loops:
break
counter += 1
else:
sleep(s)
# Draw a shape. all this needs is to set shape pattern.
# For example [[0,0,0,0,0,0,0,0], [0,1,1,0,0,1,1,0], [1,0,0,1,1,0,0,1], [1,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,1], [0,1,0,0,0,0,1,0], [0,0,1,0,0,1,0,0], [0,0,0,1,1,0,0,0]] will display a heart
def shape(self, patern = [], delay = 0):
self.display.fill(0)
for li, l in enumerate(patern):
for di, d in enumerate(l):
if d == 1:
sleep(delay)
self.display.pixel(int(di), int(li), 1)
self.display.show()