Skip to content

Commit 395cced

Browse files
committed
Merge branch 'bluejazzCHN_master' into pull/29
# Conflicts: # adafruit_max7219/max7219.py
2 parents 562c9a3 + 8f1ac59 commit 395cced

File tree

2 files changed

+65
-8
lines changed

2 files changed

+65
-8
lines changed

adafruit_max7219/max7219.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-FileCopyrightText: 2016 Philip R. Moyer for Adafruit Industries
22
# SPDX-FileCopyrightText: 2016 Radomir Dopieralski for Adafruit Industries
3+
# SPDX-FileCopyrightText: 2021 bluejazzCHN for Adafruit Industries
34
#
45
# SPDX-License-Identifier: MIT
56

@@ -24,15 +25,16 @@
2425
--------------------
2526
**Hardware:**
2627
27-
* Adafruit `MAX7219CNG LED Matrix/Digit Display Driver -
28+
* `Adafruit MAX7219CNG LED Matrix/Digit Display Driver -
2829
MAX7219 <https://www.adafruit.com/product/453>`_ (Product ID: 453)
2930
3031
**Software and Dependencies:**
3132
3233
* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards:
3334
https://github.com/adafruit/circuitpython/releases
3435
35-
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
36+
* Adafruit's Bus Device library:
37+
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
3638
3739
**Notes:**
3840
#. Datasheet: https://cdn-shop.adafruit.com/datasheets/MAX7219.pdf
@@ -56,7 +58,6 @@
5658
class MAX7219:
5759
"""
5860
MAX2719 - driver for displays based on max719 chip_select
59-
6061
:param int width: the number of pixels wide
6162
:param int height: the number of pixels high
6263
:param object spi: an spi busio or spi bitbangio object
@@ -99,12 +100,14 @@ def brightness(self, value):
99100
raise ValueError("Brightness out of range")
100101
self.write_cmd(_INTENSITY, value)
101102

102-
def show(self):
103+
def show(self, number=1, t_num=1):
103104
"""
104105
Updates the display.
106+
:param int number: which one is in the cascaded matrixs, default is 1.
107+
:param int t_num: total number of cascaded Matrixs,default is 1.
105108
"""
106109
for ypos in range(8):
107-
self.write_cmd(_DIGIT0 + ypos, self._buffer[ypos])
110+
self.write_cmd(_DIGIT0 + ypos, self._buffer[ypos], number, t_num)
108111

109112
def fill(self, bit_value):
110113
"""
@@ -129,18 +132,30 @@ def scroll(self, delta_x, delta_y):
129132
"""Srcolls the display using delta_x,delta_y."""
130133
self.framebuf.scroll(delta_x, delta_y)
131134

132-
def write_cmd(self, cmd, data):
135+
def write_cmd(self, cmd, data, number=1, t_num=1):
133136
# pylint: disable=no-member
134-
"""Writes a command to spi device."""
137+
"""Writes a command to spi device.
138+
:param int number: whichi one is in the cascaded matrixs, default is 1.
139+
:param int t_num: total number of cascaded Matrixs,default is 1.
140+
"""
135141
# print('cmd {} data {}'.format(cmd,data))
136142
self._chip_select.value = False
143+
144+
# send Noop to ones behind number Matrix
137145
with self._spi_device as my_spi_device:
146+
for i in range(number, t_num):
147+
my_spi_device.write(bytearray([0, 0]))
148+
138149
my_spi_device.write(bytearray([cmd, data]))
139150

151+
# send Noop to all before number, if you want to know why, please ref to MAX7219.pdf.
152+
for i in range(0, number - 1):
153+
my_spi_device.write(bytearray([0, 0]))
154+
i = i - i
155+
140156
def rotation(self, direction):
141157
"""
142158
Set display direction
143-
144159
:param direction:set int to change display direction, value 0 (default), 1, 2, 3
145160
"""
146161
self.framebuf.rotation = direction

examples/max7219_cascade.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# SPDX-FileCopyrightText: 2021 bluejazzCHN for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
import time
5+
import random
6+
from board import TX, RX, A2
7+
import busio
8+
import digitalio
9+
from adafruit_max7219 import matrices
10+
11+
clk = RX
12+
din = TX
13+
cs = digitalio.DigitalInOut(A2)
14+
15+
spi = busio.SPI(clk, MOSI=din)
16+
display = matrices.Matrix8x8(spi, cs)
17+
18+
while True:
19+
display.clear_all()
20+
s = "Hello, World!"
21+
22+
# Demo One: cascaded matrix with two max7219
23+
# show random char in string s on the the first of cascaded matrixs.
24+
# show scroll string s on the second of cascaded matrixs.
25+
display.text(s[random.randint(0, len(s) - 1)], 0, 0)
26+
display.show(1, 2)
27+
28+
for c in range(len(s) * 8):
29+
display.fill(0)
30+
display.text(s, -c, 0)
31+
display.show(2, 2)
32+
time.sleep(0.25)
33+
34+
# Demo two: scroll string s on the cascaded matrix with two max7219
35+
for c in range(len(s) * 8):
36+
display.fill(0)
37+
display.text(s, -c, 0)
38+
display.show(1, 2)
39+
display.fill(0)
40+
display.text(s, -c + 8, 0)
41+
display.show(2, 2)
42+
time.sleep(0.25)

0 commit comments

Comments
 (0)