Skip to content

Commit 5ac6531

Browse files
authored
Merge pull request #22 from FoamyGuy/py_driver_pixelbuf
add write() to python driver so it can be used with pixelbuf.
2 parents 30f1b28 + 9282b23 commit 5ac6531

File tree

5 files changed

+224
-2
lines changed

5 files changed

+224
-2
lines changed

adafruit_is31fl3741/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
# Used only for typing
3434
from typing import Optional, Tuple, Union # pylint: disable=unused-import
3535
from circuitpython_typing.pil import Image
36+
from circuitpython_typing import ReadableBuffer
3637
from adafruit_framebuf import FrameBuffer
3738
import busio
3839
except ImportError:
@@ -233,6 +234,19 @@ def show(self) -> None:
233234
i2c.write(self._pixel_buffer, start=180, end=352)
234235
self._pixel_buffer[180] = save
235236

237+
def write(self, mapping: Tuple, buffer: ReadableBuffer) -> None:
238+
"""
239+
Write buf out on the I2C bus to the IS31FL3741.
240+
241+
:param mapping: map the pixels in the buffer to the order addressed by the driver chip
242+
:param buffer: The bytes to clock out. No assumption is made about color order
243+
:return: None
244+
"""
245+
for pos, data in enumerate(buffer):
246+
if mapping[pos] != 65535:
247+
self[mapping[pos]] = data
248+
self.show()
249+
236250

237251
IS3741_RGB = (0 << 4) | (1 << 2) | (2) # Encode as R,G,B
238252
IS3741_RBG = (0 << 4) | (2 << 2) | (1) # Encode as R,B,G

adafruit_is31fl3741/is31fl3741_pixelbuf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
try:
2121
# Used only for typing
22-
from typing import Optional, Type
22+
from typing import Optional, Type, Union
2323
from types import TracebackType
2424
import is31fl3741
25+
from . import IS31FL3741
2526
except ImportError:
2627
pass
2728

@@ -78,7 +79,7 @@ class IS31FL3741_PixelBuf(adafruit_pixelbuf.PixelBuf):
7879

7980
def __init__(
8081
self,
81-
is31: is31fl3741.IS31FL3741,
82+
is31: Union[is31fl3741.IS31FL3741, IS31FL3741],
8283
mapping: tuple,
8384
*,
8485
addr: int = 0x30,
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-FileCopyrightText: 2023 Neradoc https://neradoc.me
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
This example repeatedly displays all available animations
6+
on the IS31FL3741 13x9 RGB Matrix, at a five second interval.
7+
"""
8+
import board
9+
from adafruit_led_animation.animation.blink import Blink
10+
from adafruit_led_animation.animation.sparklepulse import SparklePulse
11+
from adafruit_led_animation.animation.comet import Comet
12+
from adafruit_led_animation.animation.chase import Chase
13+
from adafruit_led_animation.animation.pulse import Pulse
14+
from adafruit_led_animation.animation.sparkle import Sparkle
15+
from adafruit_led_animation.animation.rainbowchase import RainbowChase
16+
from adafruit_led_animation.animation.rainbowsparkle import RainbowSparkle
17+
from adafruit_led_animation.animation.rainbowcomet import RainbowComet
18+
from adafruit_led_animation.animation.solid import Solid
19+
from adafruit_led_animation.animation.colorcycle import ColorCycle
20+
from adafruit_led_animation.animation.rainbow import Rainbow
21+
from adafruit_led_animation.animation.customcolorchase import CustomColorChase
22+
from adafruit_led_animation.sequence import AnimationSequence
23+
from adafruit_led_animation.color import PURPLE, WHITE, AMBER, JADE, MAGENTA, ORANGE
24+
from adafruit_is31fl3741 import PREFER_BUFFER
25+
from adafruit_is31fl3741.adafruit_rgbmatrixqt import Adafruit_RGBMatrixQT
26+
from adafruit_is31fl3741.is31fl3741_pixelbuf import IS31FL3741_PixelBuf
27+
28+
# i2c = board.I2C()
29+
i2c = board.STEMMA_I2C()
30+
31+
########################################################################
32+
# Instantiate the nice IS31FL3741
33+
########################################################################
34+
35+
is31 = Adafruit_RGBMatrixQT(i2c, allocate=PREFER_BUFFER)
36+
is31.set_led_scaling(0xFF)
37+
is31.global_current = 0xFF
38+
is31.enable = True
39+
40+
########################################################################
41+
# Setup the mapping and PixelBuf instance
42+
########################################################################
43+
44+
WIDTH = 13
45+
HEIGHT = 9
46+
LEDS_MAP = tuple(
47+
(
48+
address
49+
for y in range(HEIGHT)
50+
for x in range(WIDTH)
51+
for address in Adafruit_RGBMatrixQT.pixel_addrs(x, y)
52+
)
53+
)
54+
pixels = IS31FL3741_PixelBuf(is31, LEDS_MAP, init=False, auto_write=False)
55+
56+
########################################################################
57+
# Run animations
58+
########################################################################
59+
60+
blink = Blink(pixels, speed=0.5, color=JADE)
61+
colorcycle = ColorCycle(pixels, speed=0.4, colors=[MAGENTA, ORANGE])
62+
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)
63+
chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE)
64+
pulse = Pulse(pixels, speed=0.1, period=3, color=AMBER)
65+
sparkle = Sparkle(pixels, speed=0.1, color=PURPLE, num_sparkles=10)
66+
solid = Solid(pixels, color=JADE)
67+
rainbow = Rainbow(pixels, speed=0.1, period=2)
68+
sparkle_pulse = SparklePulse(pixels, speed=0.1, period=3, color=JADE)
69+
rainbow_comet = RainbowComet(pixels, speed=0.1, tail_length=7, bounce=True)
70+
rainbow_chase = RainbowChase(pixels, speed=0.1, size=3, spacing=2, step=8)
71+
rainbow_sparkle = RainbowSparkle(pixels, speed=0.1, num_sparkles=15)
72+
custom_color_chase = CustomColorChase(
73+
pixels, speed=0.1, size=2, spacing=3, colors=[ORANGE, WHITE, JADE]
74+
)
75+
76+
animations = AnimationSequence(
77+
comet,
78+
blink,
79+
rainbow_sparkle,
80+
chase,
81+
pulse,
82+
sparkle,
83+
rainbow,
84+
solid,
85+
rainbow_comet,
86+
sparkle_pulse,
87+
rainbow_chase,
88+
custom_color_chase,
89+
advance_interval=5,
90+
auto_clear=True,
91+
)
92+
while True:
93+
animations.animate()
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-FileCopyrightText: 2023 Neradoc https://neradoc.me
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
This example repeatedly displays all available animations
6+
on the IS31FL3741 13x9 RGB Matrix, at a five second interval.
7+
"""
8+
import board
9+
from adafruit_led_animation.animation.blink import Blink
10+
from adafruit_led_animation.animation.comet import Comet
11+
from adafruit_led_animation.animation.colorcycle import ColorCycle
12+
from adafruit_led_animation.sequence import AnimationSequence
13+
from adafruit_led_animation.color import PURPLE, JADE
14+
from adafruit_is31fl3741 import PREFER_BUFFER
15+
from adafruit_is31fl3741.adafruit_rgbmatrixqt import Adafruit_RGBMatrixQT
16+
from adafruit_is31fl3741.is31fl3741_pixelbuf import IS31FL3741_PixelBuf
17+
18+
# i2c = board.I2C()
19+
i2c = board.STEMMA_I2C()
20+
21+
########################################################################
22+
# Instantiate the nice IS31FL3741
23+
########################################################################
24+
25+
is31 = Adafruit_RGBMatrixQT(i2c, allocate=PREFER_BUFFER)
26+
is31.set_led_scaling(0xFF)
27+
is31.global_current = 0xFF
28+
is31.enable = True
29+
30+
########################################################################
31+
# Setup the mapping and PixelBuf instance
32+
########################################################################
33+
34+
WIDTH = 13
35+
HEIGHT = 9
36+
LEDS_MAP = tuple(
37+
(
38+
address
39+
for y in range(HEIGHT)
40+
for x in range(WIDTH)
41+
for address in Adafruit_RGBMatrixQT.pixel_addrs(x, y)
42+
)
43+
)
44+
pixels = IS31FL3741_PixelBuf(is31, LEDS_MAP, init=False, auto_write=False)
45+
46+
########################################################################
47+
# Run animations
48+
########################################################################
49+
50+
blink = Blink(pixels, speed=0.5, color=JADE)
51+
colorcycle = ColorCycle(pixels, speed=0.4)
52+
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)
53+
54+
55+
animations = AnimationSequence(
56+
blink,
57+
comet,
58+
colorcycle,
59+
advance_interval=5,
60+
auto_clear=True,
61+
)
62+
while True:
63+
animations.animate()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-FileCopyrightText: 2023 Neradoc https://neradoc.me
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
This example repeatedly displays all available animations
6+
on the IS31FL3741 13x9 RGB Matrix, at a five second interval.
7+
"""
8+
import board
9+
from adafruit_led_animation.animation.blink import Blink
10+
from adafruit_led_animation.color import PINK
11+
from adafruit_is31fl3741 import PREFER_BUFFER
12+
from adafruit_is31fl3741.adafruit_rgbmatrixqt import Adafruit_RGBMatrixQT
13+
from adafruit_is31fl3741.is31fl3741_pixelbuf import IS31FL3741_PixelBuf
14+
15+
16+
# i2c = board.I2C()
17+
i2c = board.STEMMA_I2C()
18+
19+
########################################################################
20+
# Instantiate the nice IS31FL3741
21+
########################################################################
22+
23+
is31 = Adafruit_RGBMatrixQT(i2c, allocate=PREFER_BUFFER)
24+
is31.set_led_scaling(0xFF)
25+
is31.global_current = 0xFF
26+
is31.enable = True
27+
28+
########################################################################
29+
# Setup the mapping and PixelBuf instance
30+
########################################################################
31+
32+
WIDTH = 13
33+
HEIGHT = 9
34+
LEDS_MAP = tuple(
35+
(
36+
address
37+
for y in range(HEIGHT)
38+
for x in range(WIDTH)
39+
for address in Adafruit_RGBMatrixQT.pixel_addrs(x, y)
40+
)
41+
)
42+
pixels = IS31FL3741_PixelBuf(is31, LEDS_MAP, init=False, auto_write=False)
43+
44+
########################################################################
45+
# Run animations
46+
########################################################################
47+
48+
blink = Blink(pixels, speed=0.5, color=PINK)
49+
50+
while True:
51+
blink.animate()

0 commit comments

Comments
 (0)