From dabc765db6a98fa70d2b70cdb6b9af90d1de954c Mon Sep 17 00:00:00 2001 From: bluejazzCHN Date: Thu, 7 Jan 2021 22:19:46 +0800 Subject: [PATCH 1/6] update --- adafruit_max7219/max7219.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 530ddd1..9f22c6b 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -149,3 +149,11 @@ def write_cmd(self, cmd, data): self._chip_select.value = False with self._spi_device as my_spi_device: my_spi_device.write(bytearray([cmd, data])) + + def rotation(self, direction): + """ + Set display direction + + :param direction:set int to change display direction, value 0 (default), 1, 2, 3 + """ + self.framebuf.rotation = direction From 25b0b3617ad01c73659b732689b765a6505452d1 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Fri, 8 Jan 2021 12:17:55 +0800 Subject: [PATCH 2/6] Update README.rst --- README.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.rst b/README.rst index aaa33a7..e93d1f2 100644 --- a/README.rst +++ b/README.rst @@ -124,3 +124,17 @@ Documentation ============= For information on building library documentation, please check out `this guide `_. + + +Additons +============= + +1. Add rotation func + +.. code-block:: python + + matrix = matrices.Matrix8x8(spi, cs) + matrix.rotation(2) + + + From 785481d1bef9c803259c2eb902fff0b468339bfb Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Fri, 8 Jan 2021 12:19:58 +0800 Subject: [PATCH 3/6] Update README.rst --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index e93d1f2..a87e1e0 100644 --- a/README.rst +++ b/README.rst @@ -73,6 +73,7 @@ adafruit_max7219.Matrix8x8 Example spi = busio.SPI(clk, MOSI=din) display = matrices.Matrix8x8(spi, cs) + display.rotation(1) #change display direction while True: display.brightness(3) From 886581da0a4f65a2ab135d2b240ab4a352a112f2 Mon Sep 17 00:00:00 2001 From: bluejazzCHN Date: Sun, 10 Jan 2021 15:29:35 +0800 Subject: [PATCH 4/6] Add function that display string on mult matrix --- .vscode/settings.json | 22 +++++++++++++ adafruit_max7219/matrices.py | 24 ++++++++++++-- adafruit_max7219/max7219.py | 31 ++++++++++++++++++- .../max7219_disaplay_string_multi_matrix.py | 20 ++++++++++++ 4 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 examples/max7219_disaplay_string_multi_matrix.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2fe040b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,22 @@ +{ + "MicroPython.executeButton": [ + { + "text": "▶", + "tooltip": "运行", + "alignment": "left", + "command": "extension.executeFile", + "priority": 3.5 + } + ], + "MicroPython.syncButton": [ + { + "text": "$(sync)", + "tooltip": "同步", + "alignment": "left", + "command": "extension.execute", + "priority": 4 + } + ], + "python.linting.pylintEnabled": true, + "python.pythonPath": "/usr/bin/python3" +} \ No newline at end of file diff --git a/adafruit_max7219/matrices.py b/adafruit_max7219/matrices.py index 139076f..19bec26 100644 --- a/adafruit_max7219/matrices.py +++ b/adafruit_max7219/matrices.py @@ -27,6 +27,7 @@ """ from micropython import const from adafruit_max7219 import max7219 +import time __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MAX7219.git" @@ -45,8 +46,8 @@ class Matrix8x8(max7219.MAX7219): :param ~digitalio.DigitalInOut cs: digital in/out to use as chip select signal """ - def __init__(self, spi, cs): - super().__init__(8, 8, spi, cs) + def __init__(self, spi, cs,num=1): + super().__init__(8, 8, spi, cs,num=num) def init_display(self): for cmd, data in ( @@ -56,7 +57,7 @@ def init_display(self): (_DECODEMODE, 0), (_SHUTDOWN, 1), ): - self.write_cmd(cmd, data) + self._write([cmd,data]*self.num) self.fill(0) self.show() @@ -77,3 +78,20 @@ def clear_all(self): Clears all matrix leds. """ self.fill(0) + + def display_str(self, data, delay=1): + """ + Display string on led matrix by matrix length + + :param str: string that can be of any length. + :param delay: transfer time from one screen to another screen. default value is 1s + + """ + i = -1 + for char in data: + i+=1 + self.fill(0) + self.text(char,1,0) + self.show_char_position(i%self.num) + if i%self.num == self.num -1: + time.sleep(delay) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 9f22c6b..1f09cac 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -66,6 +66,9 @@ _DIGIT0 = const(1) _INTENSITY = const(10) +MAX7219_REG_NOOP = 0x0 + + class MAX7219: """ @@ -81,7 +84,7 @@ class MAX7219: """ def __init__( - self, width, height, spi, cs, *, baudrate=8000000, polarity=0, phase=0 + self, width, height, spi, cs, *, baudrate=8000000, polarity=0, phase=0,num=1 ): self._chip_select = cs @@ -96,6 +99,8 @@ def __init__( self.width = width self.height = height + self.num = num + self.init_display() @@ -157,3 +162,27 @@ def rotation(self, direction): :param direction:set int to change display direction, value 0 (default), 1, 2, 3 """ self.framebuf.rotation = direction + + + def _write(self, data): + """ + Send the bytes (which should comprise of alternating command, data values) over the SPI device. + + :param data: command collections + """ + + self._chip_select.value=False + with self._spi_device as my_spi_device: + my_spi_device.write(bytes(data)) + self._chip_select.value=True + + + def show_char_position(self,position=0): + """ + write data to the position that is one of multi led matrix + + :param position: the position of matrix, value begin 0. + + """ + for ypos in range(8): + self._write([_DIGIT0 + ypos, self._buffer[ypos]]+([MAX7219_REG_NOOP, 0] *(position))) diff --git a/examples/max7219_disaplay_string_multi_matrix.py b/examples/max7219_disaplay_string_multi_matrix.py new file mode 100644 index 0000000..445d2c2 --- /dev/null +++ b/examples/max7219_disaplay_string_multi_matrix.py @@ -0,0 +1,20 @@ +# Display string on multi led matrix at any position +# Author: songjiangzhang@hotmail.com +# This sample use EPS32 S2 Board + +from adafruit_max7219 import matrices +import board +import busio +import digitalio + +clk = board.IO4 +din = board.IO2 +cs = digitalio.DigitalInOut(board.IO3) + +spi = busio.SPI(clk, MOSI=din) +display = matrices.Matrix8x8(spi, cs,4) +display.framebuf.rotation =1 # rotate screen + +display.clear_all() +while True: + display.display_str('abc7568123456789asdfghj',2) From 8e8807bc4286e71c10bbdbbf3b65112486168f43 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Sun, 10 Jan 2021 16:31:26 +0800 Subject: [PATCH 5/6] Delete settings.json --- .vscode/settings.json | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 2fe040b..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "MicroPython.executeButton": [ - { - "text": "▶", - "tooltip": "运行", - "alignment": "left", - "command": "extension.executeFile", - "priority": 3.5 - } - ], - "MicroPython.syncButton": [ - { - "text": "$(sync)", - "tooltip": "同步", - "alignment": "left", - "command": "extension.execute", - "priority": 4 - } - ], - "python.linting.pylintEnabled": true, - "python.pythonPath": "/usr/bin/python3" -} \ No newline at end of file From a63e02eef71712450536a7e6e2a6314f16687b2e Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Sun, 10 Jan 2021 16:44:24 +0800 Subject: [PATCH 6/6] Update max7219_disaplay_string_multi_matrix.py --- examples/max7219_disaplay_string_multi_matrix.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/max7219_disaplay_string_multi_matrix.py b/examples/max7219_disaplay_string_multi_matrix.py index 445d2c2..850882c 100644 --- a/examples/max7219_disaplay_string_multi_matrix.py +++ b/examples/max7219_disaplay_string_multi_matrix.py @@ -1,7 +1,3 @@ -# Display string on multi led matrix at any position -# Author: songjiangzhang@hotmail.com -# This sample use EPS32 S2 Board - from adafruit_max7219 import matrices import board import busio