Skip to content

Commit 3cefe12

Browse files
authored
Merge pull request #1 from jposada202020/pull/29
Pull/29
2 parents 8f1ac59 + 395cced commit 3cefe12

File tree

4 files changed

+87
-4
lines changed

4 files changed

+87
-4
lines changed

README.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ adafruit_max7219.Matrix8x8 Example
7373
7474
spi = busio.SPI(clk, MOSI=din)
7575
display = matrices.Matrix8x8(spi, cs)
76+
display.rotation(1) #change display direction
7677
while True:
7778
display.brightness(3)
7879
@@ -124,3 +125,14 @@ Documentation
124125
=============
125126

126127
For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.
128+
129+
130+
Additons
131+
=============
132+
133+
1. Add rotation func
134+
135+
.. code-block:: python
136+
137+
matrix = matrices.Matrix8x8(spi, cs)
138+
matrix.rotation(2)

adafruit_max7219/matrices.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
`adafruit_max7219.matrices.Matrix8x8`
77
====================================================
88
"""
9+
import time
910
from micropython import const
1011
from adafruit_max7219 import max7219
1112

13+
1214
__version__ = "0.0.0-auto.0"
1315
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MAX7219.git"
1416

@@ -26,8 +28,8 @@ class Matrix8x8(max7219.MAX7219):
2628
:param ~digitalio.DigitalInOut cs: digital in/out to use as chip select signal
2729
"""
2830

29-
def __init__(self, spi, cs):
30-
super().__init__(8, 8, spi, cs)
31+
def __init__(self, spi, cs, num=1):
32+
super().__init__(8, 8, spi, cs, num=num)
3133

3234
def init_display(self):
3335
for cmd, data in (
@@ -37,7 +39,7 @@ def init_display(self):
3739
(_DECODEMODE, 0),
3840
(_SHUTDOWN, 1),
3941
):
40-
self.write_cmd(cmd, data)
42+
self._write([cmd, data] * self.num)
4143

4244
self.fill(0)
4345
self.show()
@@ -58,3 +60,20 @@ def clear_all(self):
5860
Clears all matrix leds.
5961
"""
6062
self.fill(0)
63+
64+
def display_str(self, data, delay=1):
65+
"""
66+
Display string on led matrix by matrix length
67+
68+
:param str: string that can be of any length.
69+
:param delay: transfer time from one screen to another screen. default value is 1s
70+
71+
"""
72+
i = -1
73+
for char in data:
74+
i += 1
75+
self.fill(0)
76+
self.text(char, 1, 0)
77+
self.show_char_position(i % self.num)
78+
if i % self.num == self.num - 1:
79+
time.sleep(delay)

adafruit_max7219/max7219.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
_DIGIT0 = const(1)
5353
_INTENSITY = const(10)
5454

55+
MAX7219_REG_NOOP = 0x0
56+
5557

5658
class MAX7219:
5759
"""
@@ -66,7 +68,7 @@ class MAX7219:
6668
"""
6769

6870
def __init__(
69-
self, width, height, spi, cs, *, baudrate=8000000, polarity=0, phase=0
71+
self, width, height, spi, cs, *, baudrate=8000000, polarity=0, phase=0, num=1
7072
):
7173

7274
self._chip_select = cs
@@ -81,6 +83,7 @@ def __init__(
8183

8284
self.width = width
8385
self.height = height
86+
self.num = num
8487

8588
self.init_display()
8689

@@ -90,6 +93,7 @@ def init_display(self):
9093
def brightness(self, value):
9194
"""
9295
Controls the brightness of the display.
96+
9397
:param int value: 0->15 dimmest to brightest
9498
"""
9599
if not 0 <= value <= 15:
@@ -108,13 +112,15 @@ def show(self, number=1, t_num=1):
108112
def fill(self, bit_value):
109113
"""
110114
Fill the display buffer.
115+
111116
:param int bit_value: value > 0 set the buffer bit, else clears the buffer bit
112117
"""
113118
self.framebuf.fill(bit_value)
114119

115120
def pixel(self, xpos, ypos, bit_value=None):
116121
"""
117122
Set one buffer bit
123+
118124
:param xpos: x position to set bit
119125
:param ypos: y position to set bit
120126
:param int bit_value: value > 0 sets the buffer bit, else clears the buffer bit
@@ -153,3 +159,29 @@ def rotation(self, direction):
153159
:param direction:set int to change display direction, value 0 (default), 1, 2, 3
154160
"""
155161
self.framebuf.rotation = direction
162+
163+
def _write(self, data):
164+
"""
165+
Send the bytes (which should comprise of alternating command, data values)
166+
over the SPI device.
167+
168+
:param data: command collections
169+
"""
170+
171+
self._chip_select.value = False
172+
with self._spi_device as my_spi_device:
173+
my_spi_device.write(bytes(data))
174+
self._chip_select.value = True
175+
176+
def show_char_position(self, position=0):
177+
"""
178+
write data to the position that is one of multi led matrix
179+
180+
:param position: the position of matrix, value begin 0.
181+
182+
"""
183+
for ypos in range(8):
184+
self._write(
185+
[_DIGIT0 + ypos, self._buffer[ypos]]
186+
+ ([MAX7219_REG_NOOP, 0] * (position))
187+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
5+
import board
6+
import busio
7+
import digitalio
8+
from adafruit_max7219 import matrices
9+
10+
clk = board.IO4
11+
din = board.IO2
12+
cs = digitalio.DigitalInOut(board.IO3)
13+
14+
spi = busio.SPI(clk, MOSI=din)
15+
display = matrices.Matrix8x8(spi, cs, 4)
16+
display.framebuf.rotation = 1 # rotate screen
17+
18+
display.clear_all()
19+
while True:
20+
display.display_str("abc7568123456789asdfghj", 2)

0 commit comments

Comments
 (0)