Created
January 29, 2023 05:23
-
-
Save Neradoc/70764175a20d6c274833ea0cccf26fcb to your computer and use it in GitHub Desktop.
Scroll text on the Adafruit IS31FL3741 13x9 RGB Matrix with a Frame Buffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries | |
# SPDX-FileCopyrightText: 2023 Neradoc https://neradoc.me | |
# SPDX-License-Identifier: MIT | |
""" | |
A somewhat hacky attempt at scrolling text on the IS31FL3741 13x9 Matrix | |
https://www.adafruit.com/product/5201 | |
""" | |
import time | |
import board | |
from rainbowio import colorwheel | |
from adafruit_is31fl3741.adafruit_rgbmatrixqt import Adafruit_RGBMatrixQT | |
import adafruit_is31fl3741 | |
from is31matrixqt_framebuf import IS31FrameBuffer | |
# i2c = board.I2C() | |
i2c = board.STEMMA_I2C() | |
is31 = Adafruit_RGBMatrixQT(i2c, allocate=adafruit_is31fl3741.PREFER_BUFFER) | |
is31.set_led_scaling(0xFF) | |
is31.global_current = 0xFF | |
is31.enable = True | |
fbuff = IS31FrameBuffer(is31) | |
def scroll(text, color): | |
for x in range(-13, 7 * len(text)): | |
is31.fill(0) | |
fbuff.text(text, -x, 1, color) | |
is31.show() | |
while True: | |
scroll("Hello world!", 0x00FF80) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SPDX-FileCopyrightText: 2023 Neradoc https://neradoc.me | |
# SPDX-License-Identifier: MIT | |
""" | |
""" | |
import adafruit_framebuf | |
from adafruit_is31fl3741.adafruit_rgbmatrixqt import Adafruit_RGBMatrixQT | |
def rgb_matrix_qt_mapping(): | |
mapping = [0] * (13*9*3) | |
i = 0 | |
for y in range(9): | |
for x in range(13): | |
(b, g, r) = Adafruit_RGBMatrixQT.pixel_addrs(x,y) | |
for z in (r, g, b): | |
mapping[i] = z | |
i = i + 1 | |
return mapping | |
class IS31Buffer: | |
def __init__(self, is31, mapping): | |
self.is31 = is31 | |
self.mapping = mapping | |
def __len__(self): | |
return len(self.is31) | |
def __setitem__(self, index, val): | |
if isinstance(index, slice): | |
start, stop, step = index.indices(13*9*3) | |
for val_i, in_i in enumerate(range(start, stop, step)): | |
self.is31[self.mapping[in_i]] = val[val_i] | |
else: | |
self.is31[self.mapping[index]] = val | |
def IS31FrameBuffer(is31): | |
is31_buffer = IS31Buffer(is31, rgb_matrix_qt_mapping()) | |
return adafruit_framebuf.FrameBuffer( | |
is31_buffer, 13, 9, | |
adafruit_framebuf.RGB888 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment