Skip to content

Pull/29 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -124,3 +125,14 @@ Documentation
=============

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>`_.


Additons
=============

1. Add rotation func

.. code-block:: python

matrix = matrices.Matrix8x8(spi, cs)
matrix.rotation(2)
25 changes: 22 additions & 3 deletions adafruit_max7219/matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
`adafruit_max7219.matrices.Matrix8x8`
====================================================
"""
import time
from micropython import const
from adafruit_max7219 import max7219


__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MAX7219.git"

Expand All @@ -26,8 +28,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 (
Expand All @@ -37,7 +39,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()
Expand All @@ -58,3 +60,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)
34 changes: 33 additions & 1 deletion adafruit_max7219/max7219.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
_DIGIT0 = const(1)
_INTENSITY = const(10)

MAX7219_REG_NOOP = 0x0


class MAX7219:
"""
Expand All @@ -66,7 +68,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
Expand All @@ -81,6 +83,7 @@ def __init__(

self.width = width
self.height = height
self.num = num

self.init_display()

Expand All @@ -90,6 +93,7 @@ def init_display(self):
def brightness(self, value):
"""
Controls the brightness of the display.

:param int value: 0->15 dimmest to brightest
"""
if not 0 <= value <= 15:
Expand All @@ -108,13 +112,15 @@ def show(self, number=1, t_num=1):
def fill(self, bit_value):
"""
Fill the display buffer.

:param int bit_value: value > 0 set the buffer bit, else clears the buffer bit
"""
self.framebuf.fill(bit_value)

def pixel(self, xpos, ypos, bit_value=None):
"""
Set one buffer bit

:param xpos: x position to set bit
:param ypos: y position to set bit
:param int bit_value: value > 0 sets the buffer bit, else clears the buffer bit
Expand Down Expand Up @@ -153,3 +159,29 @@ 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))
)
20 changes: 20 additions & 0 deletions examples/max7219_disaplay_string_multi_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT


import board
import busio
import digitalio
from adafruit_max7219 import matrices

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)