add write() to python driver so it can be used with pixelbuf.
This commit is contained in:
parent
30f1b28f17
commit
57ed59508e
5 changed files with 223 additions and 2 deletions
|
|
@ -33,6 +33,7 @@ try:
|
||||||
# Used only for typing
|
# Used only for typing
|
||||||
from typing import Optional, Tuple, Union # pylint: disable=unused-import
|
from typing import Optional, Tuple, Union # pylint: disable=unused-import
|
||||||
from circuitpython_typing.pil import Image
|
from circuitpython_typing.pil import Image
|
||||||
|
from circuitpython_typing import ReadableBuffer
|
||||||
from adafruit_framebuf import FrameBuffer
|
from adafruit_framebuf import FrameBuffer
|
||||||
import busio
|
import busio
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
@ -233,6 +234,18 @@ class IS31FL3741:
|
||||||
i2c.write(self._pixel_buffer, start=180, end=352)
|
i2c.write(self._pixel_buffer, start=180, end=352)
|
||||||
self._pixel_buffer[180] = save
|
self._pixel_buffer[180] = save
|
||||||
|
|
||||||
|
def write(self, mapping: Tuple, buffer: ReadableBuffer) -> None:
|
||||||
|
"""
|
||||||
|
Write buf out on the I2C bus to the IS31FL3741.
|
||||||
|
|
||||||
|
:param mapping: map the pixels in the buffer to the order addressed by the driver chip
|
||||||
|
:param buffer: The bytes to clock out. No assumption is made about color order
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
for pos, data in enumerate(buffer):
|
||||||
|
self[mapping[pos]] = data
|
||||||
|
self.show()
|
||||||
|
|
||||||
|
|
||||||
IS3741_RGB = (0 << 4) | (1 << 2) | (2) # Encode as R,G,B
|
IS3741_RGB = (0 << 4) | (1 << 2) | (2) # Encode as R,G,B
|
||||||
IS3741_RBG = (0 << 4) | (2 << 2) | (1) # Encode as R,B,G
|
IS3741_RBG = (0 << 4) | (2 << 2) | (1) # Encode as R,B,G
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,10 @@ import adafruit_pixelbuf
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Used only for typing
|
# Used only for typing
|
||||||
from typing import Optional, Type
|
from typing import Optional, Type, Union
|
||||||
from types import TracebackType
|
from types import TracebackType
|
||||||
import is31fl3741
|
import is31fl3741
|
||||||
|
from . import IS31FL3741
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -78,7 +79,7 @@ class IS31FL3741_PixelBuf(adafruit_pixelbuf.PixelBuf):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
is31: is31fl3741.IS31FL3741,
|
is31: Union[is31fl3741.IS31FL3741, IS31FL3741],
|
||||||
mapping: tuple,
|
mapping: tuple,
|
||||||
*,
|
*,
|
||||||
addr: int = 0x30,
|
addr: int = 0x30,
|
||||||
|
|
|
||||||
93
examples/is31fl3741_rgbmatrix_all_animations.py
Normal file
93
examples/is31fl3741_rgbmatrix_all_animations.py
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
||||||
|
# SPDX-FileCopyrightText: 2023 Neradoc https://neradoc.me
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
"""
|
||||||
|
This example repeatedly displays all available animations
|
||||||
|
on the IS31FL3741 13x9 RGB Matrix, at a five second interval.
|
||||||
|
"""
|
||||||
|
import board
|
||||||
|
from adafruit_led_animation.animation.blink import Blink
|
||||||
|
from adafruit_led_animation.animation.sparklepulse import SparklePulse
|
||||||
|
from adafruit_led_animation.animation.comet import Comet
|
||||||
|
from adafruit_led_animation.animation.chase import Chase
|
||||||
|
from adafruit_led_animation.animation.pulse import Pulse
|
||||||
|
from adafruit_led_animation.animation.sparkle import Sparkle
|
||||||
|
from adafruit_led_animation.animation.rainbowchase import RainbowChase
|
||||||
|
from adafruit_led_animation.animation.rainbowsparkle import RainbowSparkle
|
||||||
|
from adafruit_led_animation.animation.rainbowcomet import RainbowComet
|
||||||
|
from adafruit_led_animation.animation.solid import Solid
|
||||||
|
from adafruit_led_animation.animation.colorcycle import ColorCycle
|
||||||
|
from adafruit_led_animation.animation.rainbow import Rainbow
|
||||||
|
from adafruit_led_animation.animation.customcolorchase import CustomColorChase
|
||||||
|
from adafruit_led_animation.sequence import AnimationSequence
|
||||||
|
from adafruit_led_animation.color import PURPLE, WHITE, AMBER, JADE, MAGENTA, ORANGE
|
||||||
|
from adafruit_is31fl3741 import PREFER_BUFFER
|
||||||
|
from adafruit_is31fl3741.adafruit_rgbmatrixqt import Adafruit_RGBMatrixQT
|
||||||
|
from adafruit_is31fl3741.is31fl3741_pixelbuf import IS31FL3741_PixelBuf
|
||||||
|
|
||||||
|
# i2c = board.I2C()
|
||||||
|
i2c = board.STEMMA_I2C()
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Instantiate the nice IS31FL3741
|
||||||
|
########################################################################
|
||||||
|
|
||||||
|
is31 = Adafruit_RGBMatrixQT(i2c, allocate=PREFER_BUFFER)
|
||||||
|
is31.set_led_scaling(0xFF)
|
||||||
|
is31.global_current = 0xFF
|
||||||
|
is31.enable = True
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Setup the mapping and PixelBuf instance
|
||||||
|
########################################################################
|
||||||
|
|
||||||
|
WIDTH = 13
|
||||||
|
HEIGHT = 9
|
||||||
|
LEDS_MAP = tuple(
|
||||||
|
(
|
||||||
|
address
|
||||||
|
for y in range(HEIGHT)
|
||||||
|
for x in range(WIDTH)
|
||||||
|
for address in Adafruit_RGBMatrixQT.pixel_addrs(x, y)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
pixels = IS31FL3741_PixelBuf(is31, LEDS_MAP, init=False, auto_write=False)
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Run animations
|
||||||
|
########################################################################
|
||||||
|
|
||||||
|
blink = Blink(pixels, speed=0.5, color=JADE)
|
||||||
|
colorcycle = ColorCycle(pixels, speed=0.4, colors=[MAGENTA, ORANGE])
|
||||||
|
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)
|
||||||
|
chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE)
|
||||||
|
pulse = Pulse(pixels, speed=0.1, period=3, color=AMBER)
|
||||||
|
sparkle = Sparkle(pixels, speed=0.1, color=PURPLE, num_sparkles=10)
|
||||||
|
solid = Solid(pixels, color=JADE)
|
||||||
|
rainbow = Rainbow(pixels, speed=0.1, period=2)
|
||||||
|
sparkle_pulse = SparklePulse(pixels, speed=0.1, period=3, color=JADE)
|
||||||
|
rainbow_comet = RainbowComet(pixels, speed=0.1, tail_length=7, bounce=True)
|
||||||
|
rainbow_chase = RainbowChase(pixels, speed=0.1, size=3, spacing=2, step=8)
|
||||||
|
rainbow_sparkle = RainbowSparkle(pixels, speed=0.1, num_sparkles=15)
|
||||||
|
custom_color_chase = CustomColorChase(
|
||||||
|
pixels, speed=0.1, size=2, spacing=3, colors=[ORANGE, WHITE, JADE]
|
||||||
|
)
|
||||||
|
|
||||||
|
animations = AnimationSequence(
|
||||||
|
comet,
|
||||||
|
blink,
|
||||||
|
rainbow_sparkle,
|
||||||
|
chase,
|
||||||
|
pulse,
|
||||||
|
sparkle,
|
||||||
|
rainbow,
|
||||||
|
solid,
|
||||||
|
rainbow_comet,
|
||||||
|
sparkle_pulse,
|
||||||
|
rainbow_chase,
|
||||||
|
custom_color_chase,
|
||||||
|
advance_interval=5,
|
||||||
|
auto_clear=True,
|
||||||
|
)
|
||||||
|
while True:
|
||||||
|
animations.animate()
|
||||||
63
examples/is31fl3741_rgbmatrix_animation_sequence.py
Normal file
63
examples/is31fl3741_rgbmatrix_animation_sequence.py
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
||||||
|
# SPDX-FileCopyrightText: 2023 Neradoc https://neradoc.me
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
"""
|
||||||
|
This example repeatedly displays all available animations
|
||||||
|
on the IS31FL3741 13x9 RGB Matrix, at a five second interval.
|
||||||
|
"""
|
||||||
|
import board
|
||||||
|
from adafruit_led_animation.animation.blink import Blink
|
||||||
|
from adafruit_led_animation.animation.comet import Comet
|
||||||
|
from adafruit_led_animation.animation.colorcycle import ColorCycle
|
||||||
|
from adafruit_led_animation.sequence import AnimationSequence
|
||||||
|
from adafruit_led_animation.color import PURPLE, JADE
|
||||||
|
from adafruit_is31fl3741 import PREFER_BUFFER
|
||||||
|
from adafruit_is31fl3741.adafruit_rgbmatrixqt import Adafruit_RGBMatrixQT
|
||||||
|
from adafruit_is31fl3741.is31fl3741_pixelbuf import IS31FL3741_PixelBuf
|
||||||
|
|
||||||
|
# i2c = board.I2C()
|
||||||
|
i2c = board.STEMMA_I2C()
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Instantiate the nice IS31FL3741
|
||||||
|
########################################################################
|
||||||
|
|
||||||
|
is31 = Adafruit_RGBMatrixQT(i2c, allocate=PREFER_BUFFER)
|
||||||
|
is31.set_led_scaling(0xFF)
|
||||||
|
is31.global_current = 0xFF
|
||||||
|
is31.enable = True
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Setup the mapping and PixelBuf instance
|
||||||
|
########################################################################
|
||||||
|
|
||||||
|
WIDTH = 13
|
||||||
|
HEIGHT = 9
|
||||||
|
LEDS_MAP = tuple(
|
||||||
|
(
|
||||||
|
address
|
||||||
|
for y in range(HEIGHT)
|
||||||
|
for x in range(WIDTH)
|
||||||
|
for address in Adafruit_RGBMatrixQT.pixel_addrs(x, y)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
pixels = IS31FL3741_PixelBuf(is31, LEDS_MAP, init=False, auto_write=False)
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Run animations
|
||||||
|
########################################################################
|
||||||
|
|
||||||
|
blink = Blink(pixels, speed=0.5, color=JADE)
|
||||||
|
colorcycle = ColorCycle(pixels, speed=0.4)
|
||||||
|
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)
|
||||||
|
|
||||||
|
|
||||||
|
animations = AnimationSequence(
|
||||||
|
blink,
|
||||||
|
comet,
|
||||||
|
colorcycle,
|
||||||
|
advance_interval=5,
|
||||||
|
auto_clear=True,
|
||||||
|
)
|
||||||
|
while True:
|
||||||
|
animations.animate()
|
||||||
51
examples/is31fl3741_rgbmatrix_led_animation.py
Normal file
51
examples/is31fl3741_rgbmatrix_led_animation.py
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
||||||
|
# SPDX-FileCopyrightText: 2023 Neradoc https://neradoc.me
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
"""
|
||||||
|
This example repeatedly displays all available animations
|
||||||
|
on the IS31FL3741 13x9 RGB Matrix, at a five second interval.
|
||||||
|
"""
|
||||||
|
import board
|
||||||
|
from adafruit_led_animation.animation.blink import Blink
|
||||||
|
from adafruit_led_animation.color import PINK
|
||||||
|
from adafruit_is31fl3741 import PREFER_BUFFER
|
||||||
|
from adafruit_is31fl3741.adafruit_rgbmatrixqt import Adafruit_RGBMatrixQT
|
||||||
|
from adafruit_is31fl3741.is31fl3741_pixelbuf import IS31FL3741_PixelBuf
|
||||||
|
|
||||||
|
|
||||||
|
# i2c = board.I2C()
|
||||||
|
i2c = board.STEMMA_I2C()
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Instantiate the nice IS31FL3741
|
||||||
|
########################################################################
|
||||||
|
|
||||||
|
is31 = Adafruit_RGBMatrixQT(i2c, allocate=PREFER_BUFFER)
|
||||||
|
is31.set_led_scaling(0xFF)
|
||||||
|
is31.global_current = 0xFF
|
||||||
|
is31.enable = True
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Setup the mapping and PixelBuf instance
|
||||||
|
########################################################################
|
||||||
|
|
||||||
|
WIDTH = 13
|
||||||
|
HEIGHT = 9
|
||||||
|
LEDS_MAP = tuple(
|
||||||
|
(
|
||||||
|
address
|
||||||
|
for y in range(HEIGHT)
|
||||||
|
for x in range(WIDTH)
|
||||||
|
for address in Adafruit_RGBMatrixQT.pixel_addrs(x, y)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
pixels = IS31FL3741_PixelBuf(is31, LEDS_MAP, init=False, auto_write=False)
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Run animations
|
||||||
|
########################################################################
|
||||||
|
|
||||||
|
blink = Blink(pixels, speed=0.5, color=PINK)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
blink.animate()
|
||||||
Loading…
Reference in a new issue