Compare commits

...

1 commit

Author SHA1 Message Date
TrevKnows
c7b011a71b Added PyLeap_CPB_IS31FL3741 for PyLeap Demo 2021-09-27 17:21:51 -04:00
12 changed files with 801 additions and 0 deletions

View file

@ -0,0 +1,275 @@
# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
`adafruit_is31fl3741`
====================================================
CircuitPython driver for the IS31FL3741 RGB Matrix IC.
Base library.
* Author(s): Ladyada
Implementation Notes
--------------------
**Hardware:**
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases
"""
from adafruit_bus_device import i2c_device
from adafruit_register.i2c_struct import ROUnaryStruct, UnaryStruct
from adafruit_register.i2c_bit import RWBit
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_IS31FL3741.git"
_IS3741_ADDR_DEFAULT = 0x30
_IS3741_COMMANDREGISTER = 0xFD
_IS3741_COMMANDREGISTERLOCK = 0xFE
_IS3741_INTMASKREGISTER = 0xF0
_IS3741_INTSTATUSREGISTER = 0xF1
_IS3741_IDREGISTER = 0xFC
_IS3741_FUNCREG_CONFIG = 0x00
_IS3741_FUNCREG_GCURRENT = 0x01
_IS3741_FUNCREG_RESET = 0x3F
# Buffer allocation behaviors passed to constructor
NO_BUFFER = 0x00 # DO NOT buffer pixel data, write pixels as needed
PREFER_BUFFER = 0x01 # OPTIONALLY buffer pixel data, RAM permitting
MUST_BUFFER = 0x02 # MUST buffer pixel data, else throw MemoryError
class IS31FL3741:
"""
The IS31FL3741 is an abstract class contain the main function related to this chip.
Each board needs to define width, height and pixel_addr.
:param ~adafruit_bus_device.i2c_device i2c_device: the connected i2c bus i2c_device
:param address: the device address; defaults to 0x30
:param allocate: buffer allocation strategy: NO_BUFFER = pixels are always
sent to device as they're set. PREFER_BUFFER = RAM
permitting, buffer pixels in RAM, updating device only
when show() is called, but fall back on NO_BUFFER
behavior. MUST_BUFFER = buffer pixels in RAM, throw
MemoryError if allocation fails.
"""
width = 13
height = 9
_page_reg = UnaryStruct(_IS3741_COMMANDREGISTER, "<B")
_lock_reg = UnaryStruct(_IS3741_COMMANDREGISTERLOCK, "<B")
_id_reg = UnaryStruct(_IS3741_IDREGISTER, "<B")
_config_reg = UnaryStruct(_IS3741_FUNCREG_CONFIG, "<B")
_gcurrent_reg = UnaryStruct(_IS3741_FUNCREG_GCURRENT, "<B")
_reset_reg = UnaryStruct(_IS3741_FUNCREG_RESET, "<B")
_shutdown_bit = RWBit(_IS3741_FUNCREG_CONFIG, 0)
_pixel_buffer = None
def __init__(self, i2c, address=_IS3741_ADDR_DEFAULT, allocate=NO_BUFFER):
if allocate >= PREFER_BUFFER:
try:
# Pixel buffer intentionally has an extra item at the start
# (value of 0) so we can i2c.write() from the buffer directly
# (don't need a temp/copy buffer to pre-pend the register
# address).
self._pixel_buffer = bytearray(352)
except MemoryError:
if allocate == MUST_BUFFER:
raise
self.i2c_device = i2c_device.I2CDevice(i2c, address)
if self._id_reg != 2 * address:
raise AttributeError("Cannot find a IS31FL3741 at address 0x", address)
self._buf = bytearray(2)
self._page = None
self.reset()
def reset(self):
"""Reset"""
self.page = 4
self._reset_reg = 0xAE
def unlock(self):
"""Unlock"""
self._lock_reg = 0xC5
def set_led_scaling(self, scale):
"""Set LED scaling.
param scale: The scale.
"""
scalebuf = [scale] * 181
scalebuf[0] = 0
self.page = 2
with self.i2c_device as i2c:
i2c.write(bytes(scalebuf))
self.page = 3
with self.i2c_device as i2c:
i2c.write(bytes(scalebuf))
@property
def global_current(self):
"""Global current"""
self.page = 4
return self._gcurrent_reg
@global_current.setter
def global_current(self, current):
self.page = 4
self._gcurrent_reg = current
@property
def enable(self):
"""Enable"""
self.page = 4
return self._shutdown_bit
@enable.setter
def enable(self, enable):
self.page = 4
self._shutdown_bit = enable
@property
def page(self):
"""Page"""
return self._page
@page.setter
def page(self, page_value):
if page_value == self._page:
return # already set
if page_value > 4:
raise ValueError("Page must be 0 ~ 4")
self._page = page_value # cache
self.unlock()
self._page_reg = page_value
def __getitem__(self, led):
if not 0 <= led <= 350:
raise ValueError("LED must be 0 ~ 350")
if self._pixel_buffer:
return self._pixel_buffer[1 + led]
if led < 180:
self.page = 0
self._buf[0] = led
else:
self.page = 1
self._buf[0] = led - 180
with self.i2c_device as i2c:
i2c.write_then_readinto(
self._buf, self._buf, out_start=0, out_end=1, in_start=1, in_end=2
)
return self._buf[1]
def __setitem__(self, led, pwm):
if not 0 <= led <= 350:
raise ValueError("LED must be 0 ~ 350")
if not 0 <= pwm <= 255:
raise ValueError("PWM must be 0 ~ 255")
# print(led, pwm)
if self._pixel_buffer:
self._pixel_buffer[1 + led] = pwm
else:
if led < 180:
self.page = 0
self._buf[0] = led
else:
self.page = 1
self._buf[0] = led - 180
self._buf[1] = pwm
with self.i2c_device as i2c:
i2c.write(self._buf)
# This function must be replaced for each board
@staticmethod
def pixel_addrs(x, y):
"""Calulate the offset into the device array for x,y pixel"""
raise NotImplementedError("Supported in subclasses only")
# pylint: disable-msg=too-many-arguments
def pixel(self, x, y, color=None):
"""
Color of for x-, y-pixel
:param x: horizontal pixel position
:param y: vertical pixel position
:param color: hex color value 0x000000 to 0xFFFFFF
"""
if not 0 <= x <= self.width:
return None
if not 0 <= y <= self.height:
return None
addrs = self.pixel_addrs(x, y)
# print(addrs)
if color is not None: # set the color
self[addrs[0]] = (color >> 16) & 0xFF
self[addrs[1]] = (color >> 8) & 0xFF
self[addrs[2]] = color & 0xFF
return None
# we want to fetch the color
color = self[addrs[0]]
color <<= 8
color |= self[addrs[1]]
color <<= 8
color |= self[addrs[2]]
return color
# pylint: enable-msg=too-many-arguments
def image(self, img):
"""Set buffer to value of Python Imaging Library image. The image should
be in 8-bit mode (L) and a size equal to the display size.
:param img: Python Imaging Library image
"""
if img.mode != "RGB":
raise ValueError("Image must be in mode RGB.")
imwidth, imheight = img.size
if imwidth != self.width or imheight != self.height:
raise ValueError(
"Image must be same dimensions as display ({0}x{1}).".format(
self.width, self.height
)
)
# Grab all the pixels from the image, faster than getpixel.
pixels = img.load()
# Iterate through the pixels
for x in range(self.width): # yes this double loop is slow,
for y in range(self.height): # but these displays are small!
self.pixel(x, y, pixels[(x, y)])
def show(self):
"""Issue in-RAM pixel data to device. No effect if pixels are
unbuffered.
"""
if self._pixel_buffer:
self.page = 0
with self.i2c_device as i2c:
# _pixel_buffer[0] is always 0! (First register addr)
i2c.write(self._pixel_buffer, start=0, end=181)
self.page = 1
with self.i2c_device as i2c:
# In order to write from pixel buffer directly (without a
# whole extra temp buffer), element 180 is saved in a temp var
# and replaced with 0 (representing the first regisyer addr on
# page 1), then we can i2c.write() directly from that position
# in the buffer. Element 180 is restored afterward. This is
# the same strategy as used in the Arduino library.
# 'end' below is 352 (not 351) because of the extra byte at
# the start of the pixel buffer.
save = self._pixel_buffer[180]
self._pixel_buffer[180] = 0
i2c.write(self._pixel_buffer, start=180, end=352)
self._pixel_buffer[180] = save

View file

@ -0,0 +1,392 @@
# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries, Rose Hooper
#
# SPDX-License-Identifier: MIT
"""
`adafruit_is31fl3741.adafruit_rgbmatrixqt`
====================================================
CircuitPython driver for the Adafruit IS31FL3741 RGB Matrix QT board
* Author(s): ladyada, Rose Hooper
Implementation Notes
--------------------
**Hardware:**
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases
"""
from struct import unpack_from
import adafruit_is31fl3741
from . import IS31FL3741
class Right_Ring:
"""The right eye ring of the LED glasses"""
# ledmap = ( # These are BRG order; reordered to RGB in bytes below
# (287, 31, 30), # 0
# (278, 1, 0), # 1
# (273, 274, 275), # 2
# (282, 283, 284), # 3
# (270, 271, 272), # 4
# (27, 28, 29), # 5
# (23, 24, 25), # 6
# (276, 277, 22), # 7
# (20, 21, 26), # 8
# (50, 51, 56), # 9
# (80, 81, 86), # 10
# (110, 111, 116), # 11
# (140, 141, 146), # 12
# (170, 171, 176), # 13
# (200, 201, 206), # 14
# (230, 231, 236), # 15
# (260, 261, 266), # 16
# (348, 349, 262), # 17
# (233, 234, 235), # 18
# (237, 238, 239), # 19
# (339, 340, 232), # 20
# (327, 328, 329), # 21
# (305, 91, 90), # 22
# (296, 61, 60), # 23
# )
ledmap_bytes = (
b"\x00\x1F\x00\x1E\x01\x1F"
b"\x00\x01\x00\x00\x01\x16"
b"\x01\x12\x01\x13\x01\x11"
b"\x01\x1B\x01\x1C\x01\x1A"
b"\x01\x0F\x01\x10\x01\x0E"
b"\x00\x1C\x00\x1D\x00\x1B"
b"\x00\x18\x00\x19\x00\x17"
b"\x01\x15\x00\x16\x01\x14"
b"\x00\x15\x00\x1A\x00\x14"
b"\x00\x33\x00\x38\x00\x32"
b"\x00\x51\x00\x56\x00\x50"
b"\x00\x6F\x00\x74\x00\x6E"
b"\x00\x8D\x00\x92\x00\x8C"
b"\x00\xAB\x00\xB0\x00\xAA"
b"\x00\xC9\x00\xCE\x00\xC8"
b"\x00\xE7\x00\xEC\x00\xE6"
b"\x01\x05\x01\x0A\x01\x04"
b"\x01\x5D\x01\x06\x01\x5C"
b"\x00\xEA\x00\xEB\x00\xE9"
b"\x00\xEE\x00\xEF\x00\xED"
b"\x01\x54\x00\xE8\x01\x53"
b"\x01\x48\x01\x49\x01\x47"
b"\x00\x5B\x00\x5A\x01\x31"
b"\x00\x3D\x00\x3C\x01\x28"
)
def __init__(self, is31_controller):
self._is31 = is31_controller
def __setitem__(self, led, color):
if not 0 <= led <= 23:
raise ValueError("led must be 0~23")
rgb = unpack_from(">HHH", self.ledmap_bytes, led * 6)
self._is31[rgb[0]] = (color >> 16) & 0xFF
self._is31[rgb[1]] = (color >> 8) & 0xFF
self._is31[rgb[2]] = color & 0xFF
def __getitem__(self, led):
if not 0 <= led <= 23:
raise ValueError("led must be 0~23")
rgb = unpack_from(">HHH", self.ledmap_bytes, led * 6)
return (
(self._is31[rgb[0]] << 16) | (self._is31[rgb[1]] << 8) | self._is31[rgb[2]]
)
class Left_Ring:
"""The left eye ring of the LED glasses"""
# ledmap = ( # These are BRG order; reordered to RGB in bytes below
# (341, 211, 210), # 0
# (332, 181, 180), # 1
# (323, 151, 150), # 2
# (127, 126, 125), # 3
# (154, 153, 152), # 4
# (163, 162, 161), # 5
# (166, 165, 164), # 6
# (244, 243, 242), # 7
# (259, 258, 257), # 8
# (169, 168, 167), # 9
# (139, 138, 137), # 10
# (109, 108, 107), # 11
# (79, 78, 77), # 12
# (49, 48, 47), # 13
# (199, 198, 197), # 14
# (229, 228, 227), # 15
# (19, 18, 17), # 16
# (4, 3, 2), # 17
# (16, 15, 14), # 18
# (13, 12, 11), # 19
# (10, 9, 8), # 20
# (217, 216, 215), # 21
# (7, 6, 5), # 22
# (350, 241, 240), # 23
# )
ledmap_bytes = (
b"\x00\xD3\x00\xD2\x01\x55"
b"\x00\xB5\x00\xB4\x01\x4C"
b"\x00\x97\x00\x96\x01\x43"
b"\x00\x7E\x00\x7D\x00\x7F"
b"\x00\x99\x00\x98\x00\x9A"
b"\x00\xA2\x00\xA1\x00\xA3"
b"\x00\xA5\x00\xA4\x00\xA6"
b"\x00\xF3\x00\xF2\x00\xF4"
b"\x01\x02\x01\x01\x01\x03"
b"\x00\xA8\x00\xA7\x00\xA9"
b"\x00\x8A\x00\x89\x00\x8B"
b"\x00\x6C\x00\x6B\x00\x6D"
b"\x00\x4E\x00\x4D\x00\x4F"
b"\x00\x30\x00\x2F\x00\x31"
b"\x00\xC6\x00\xC5\x00\xC7"
b"\x00\xE4\x00\xE3\x00\xE5"
b"\x00\x12\x00\x11\x00\x13"
b"\x00\x03\x00\x02\x00\x04"
b"\x00\x0F\x00\x0E\x00\x10"
b"\x00\x0C\x00\x0B\x00\x0D"
b"\x00\x09\x00\x08\x00\x0A"
b"\x00\xD8\x00\xD7\x00\xD9"
b"\x00\x06\x00\x05\x00\x07"
b"\x00\xF1\x00\xF0\x01\x5E"
)
def __init__(self, is31_controller):
self._is31 = is31_controller
def __setitem__(self, led, color):
if not 0 <= led <= 23:
raise ValueError("led must be 0~23")
rgb = unpack_from(">HHH", self.ledmap_bytes, led * 6)
self._is31[rgb[0]] = (color >> 16) & 0xFF
self._is31[rgb[1]] = (color >> 8) & 0xFF
self._is31[rgb[2]] = color & 0xFF
def __getitem__(self, led):
if not 0 <= led <= 23:
raise ValueError("led must be 0~23")
rgb = unpack_from(">HHH", self.ledmap_bytes, led * 6)
return (
(self._is31[rgb[0]] << 16) | (self._is31[rgb[1]] << 8) | self._is31[rgb[2]]
)
class LED_Glasses(IS31FL3741):
"""Class representing LED Glasses"""
# ledmap = ( # These are RGB order
# (None, None, None),
# (216, 215, 217),
# (186, 185, 187),
# (36, 35, 37),
# (66, 65, 67),
# (96, 95, 97),
# (126, 125, 127),
# (156, 155, 157),
# (246, 245, 247),
# (346, 347, 345),
# (337, 338, 336),
# (328, 329, 327),
# (319, 320, 318),
# (310, 311, 309),
# (301, 302, 300),
# (292, 293, 291),
# (283, 284, 282),
# (None, None, None),
# (9, 8, 10),
# (219, 218, 220),
# (189, 188, 190),
# (39, 38, 40),
# (69, 68, 70),
# (99, 98, 100),
# (129, 128, 130),
# (159, 158, 160),
# (249, 248, 250),
# (343, 344, 342),
# (334, 335, 333),
# (325, 326, 324),
# (316, 317, 315),
# (307, 308, 306),
# (298, 299, 297),
# (289, 290, 288),
# (280, 281, 279),
# (271, 272, 270),
# (12, 11, 13),
# (222, 221, 223),
# (192, 191, 193),
# (42, 41, 43),
# (72, 71, 73),
# (102, 101, 103),
# (132, 131, 133),
# (162, 161, 163),
# (252, 251, 253),
# (268, 269, 267),
# (238, 239, 237),
# (208, 209, 207),
# (178, 179, 177),
# (148, 149, 147),
# (118, 119, 117),
# (88, 89, 87),
# (58, 59, 57),
# (28, 29, 27),
# (15, 14, 16),
# (225, 224, 226),
# (195, 194, 196),
# (45, 44, 46),
# (75, 74, 76),
# (105, 104, 106),
# (135, 134, 136),
# (165, 164, 166),
# (255, 254, 256),
# (264, 265, 263),
# (234, 235, 233),
# (204, 205, 203),
# (174, 175, 173),
# (144, 145, 143),
# (114, 115, 113),
# (84, 85, 83),
# (54, 55, 53),
# (24, 25, 23),
# (3, 2, 4),
# (213, 212, 214),
# (183, 182, 184),
# (33, 32, 34),
# (63, 62, 64),
# (93, 92, 94),
# (123, 122, 124),
# (243, 242, 244),
# (None, None, None),
# (None, None, None),
# (349, 262, 348),
# (331, 202, 330),
# (322, 172, 321),
# (313, 142, 312),
# (304, 112, 303),
# (295, 82, 294),
# (286, 52, 285),
# (277, 22, 276))
# These pixels aren't connected to anything and are safe to use for pixels that aren't visible
# unused_pixels = (120, 121, 314)
# This table has 'None' elements replaced w/unused_pixels equivalent
ledmap_bytes = (
b"\x00\x78\x00\x79\x01\x3A"
b"\x00\xD8\x00\xD7\x00\xD9"
b"\x00\xBA\x00\xB9\x00\xBB"
b"\x00\x24\x00\x23\x00\x25"
b"\x00\x42\x00\x41\x00\x43"
b"\x00\x60\x00\x5F\x00\x61"
b"\x00\x7E\x00\x7D\x00\x7F"
b"\x00\x9C\x00\x9B\x00\x9D"
b"\x00\xF6\x00\xF5\x00\xF7"
b"\x01\x5A\x01\x5B\x01\x59"
b"\x01\x51\x01\x52\x01\x50"
b"\x01\x48\x01\x49\x01\x47"
b"\x01\x3F\x01\x40\x01\x3E"
b"\x01\x36\x01\x37\x01\x35"
b"\x01\x2D\x01\x2E\x01\x2C"
b"\x01\x24\x01\x25\x01\x23"
b"\x01\x1B\x01\x1C\x01\x1A"
b"\x00\x78\x00\x79\x01\x3A"
b"\x00\x09\x00\x08\x00\x0A"
b"\x00\xDB\x00\xDA\x00\xDC"
b"\x00\xBD\x00\xBC\x00\xBE"
b"\x00\x27\x00\x26\x00\x28"
b"\x00\x45\x00\x44\x00\x46"
b"\x00\x63\x00\x62\x00\x64"
b"\x00\x81\x00\x80\x00\x82"
b"\x00\x9F\x00\x9E\x00\xA0"
b"\x00\xF9\x00\xF8\x00\xFA"
b"\x01\x57\x01\x58\x01\x56"
b"\x01\x4E\x01\x4F\x01\x4D"
b"\x01\x45\x01\x46\x01\x44"
b"\x01\x3C\x01\x3D\x01\x3B"
b"\x01\x33\x01\x34\x01\x32"
b"\x01\x2A\x01\x2B\x01\x29"
b"\x01\x21\x01\x22\x01\x20"
b"\x01\x18\x01\x19\x01\x17"
b"\x01\x0F\x01\x10\x01\x0E"
b"\x00\x0C\x00\x0B\x00\x0D"
b"\x00\xDE\x00\xDD\x00\xDF"
b"\x00\xC0\x00\xBF\x00\xC1"
b"\x00\x2A\x00\x29\x00\x2B"
b"\x00\x48\x00\x47\x00\x49"
b"\x00\x66\x00\x65\x00\x67"
b"\x00\x84\x00\x83\x00\x85"
b"\x00\xA2\x00\xA1\x00\xA3"
b"\x00\xFC\x00\xFB\x00\xFD"
b"\x01\x0C\x01\x0D\x01\x0B"
b"\x00\xEE\x00\xEF\x00\xED"
b"\x00\xD0\x00\xD1\x00\xCF"
b"\x00\xB2\x00\xB3\x00\xB1"
b"\x00\x94\x00\x95\x00\x93"
b"\x00\x76\x00\x77\x00\x75"
b"\x00\x58\x00\x59\x00\x57"
b"\x00\x3A\x00\x3B\x00\x39"
b"\x00\x1C\x00\x1D\x00\x1B"
b"\x00\x0F\x00\x0E\x00\x10"
b"\x00\xE1\x00\xE0\x00\xE2"
b"\x00\xC3\x00\xC2\x00\xC4"
b"\x00\x2D\x00\x2C\x00\x2E"
b"\x00\x4B\x00\x4A\x00\x4C"
b"\x00\x69\x00\x68\x00\x6A"
b"\x00\x87\x00\x86\x00\x88"
b"\x00\xA5\x00\xA4\x00\xA6"
b"\x00\xFF\x00\xFE\x01\x00"
b"\x01\x08\x01\x09\x01\x07"
b"\x00\xEA\x00\xEB\x00\xE9"
b"\x00\xCC\x00\xCD\x00\xCB"
b"\x00\xAE\x00\xAF\x00\xAD"
b"\x00\x90\x00\x91\x00\x8F"
b"\x00\x72\x00\x73\x00\x71"
b"\x00\x54\x00\x55\x00\x53"
b"\x00\x36\x00\x37\x00\x35"
b"\x00\x18\x00\x19\x00\x17"
b"\x00\x03\x00\x02\x00\x04"
b"\x00\xD5\x00\xD4\x00\xD6"
b"\x00\xB7\x00\xB6\x00\xB8"
b"\x00\x21\x00\x20\x00\x22"
b"\x00\x3F\x00\x3E\x00\x40"
b"\x00\x5D\x00\x5C\x00\x5E"
b"\x00\x7B\x00\x7A\x00\x7C"
b"\x00\xF3\x00\xF2\x00\xF4"
b"\x00\x78\x00\x79\x01\x3A"
b"\x00\x78\x00\x79\x01\x3A"
b"\x01\x5D\x01\x06\x01\x5C"
b"\x01\x4B\x00\xCA\x01\x4A"
b"\x01\x42\x00\xAC\x01\x41"
b"\x01\x39\x00\x8E\x01\x38"
b"\x01\x30\x00\x70\x01\x2F"
b"\x01\x27\x00\x52\x01\x26"
b"\x01\x1E\x00\x34\x01\x1D"
b"\x01\x15\x00\x16\x01\x14"
)
width = 18
height = 5
def __init__(self, i2c, allocate=adafruit_is31fl3741.NO_BUFFER):
super().__init__(i2c, allocate=allocate)
self.set_led_scaling(0xFF) # turn on LEDs all the way
self.global_current = 0xFE # set current to max
self.enable = True # enable!
self.right_ring = Right_Ring(self)
self.left_ring = Left_Ring(self)
self.grid = self
@staticmethod
def pixel_addrs(x, y):
return unpack_from(
">HHH", LED_Glasses.ledmap_bytes, ((y * LED_Glasses.width) + x) * 6
)

View file

@ -0,0 +1,72 @@
# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
`adafruit_is31fl3741.adafruit_rgbmatrixqt`
====================================================
CircuitPython driver for the Adafruit IS31FL3741 RGB Matrix QT board
* Author(s): ladyada
Implementation Notes
--------------------
**Hardware:**
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases
"""
# imports
from . import IS31FL3741
class Adafruit_RGBMatrixQT(IS31FL3741):
"""Supports the ISSI IS31FL3741 eval board"""
width = 13
height = 9
@staticmethod
def pixel_addrs(x, y):
"""Calulate the RGB offsets into the device array for x,y pixel"""
col = x
row = y
# remap the row
rowmap = [8, 5, 4, 3, 2, 1, 0, 7, 6]
row = rowmap[y]
offset = 0
if row <= 5:
if col < 10:
offset = 0x1E * row + col * 3
else:
offset = 0xB4 + 0x5A + 9 * row + (col - 10) * 3
else:
if col < 10:
offset = 0xB4 + (row - 6) * 0x1E + col * 3
else:
offset = 0xB4 + 0x5A + 9 * row + (col - 10) * 3
# print(x, ",", y, "->", hex(offset))
r_off = 0
g_off = 1
b_off = 2
if col == 12 or col % 2 == 1: # odds + last col
r_off = 2
g_off = 1
b_off = 0
else: # evens
r_off = 0
g_off = 2
b_off = 1
return (offset + r_off, offset + g_off, offset + b_off)

View file

@ -0,0 +1,47 @@
# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
`adafruit_is31fl3741.issi_evb`
====================================================
CircuitPython driver for the IS31FL3741 ISSI Eval Board
* Author(s): ladyada
Implementation Notes
--------------------
**Hardware:**
* `ISSI IS31FL3741 eval board
<https://www.digikey.com/en/products/detail/issi-integrated-silicon-solution-inc/IS31FL3741-QFLS4-EB/10243951>`_
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases
"""
# imports
from . import IS31FL3741
class ISSI_EVB(IS31FL3741):
"""Supports the ISSI IS31FL3741 eval board"""
width = 13
height = 9
@staticmethod
def pixel_addrs(x, y):
"""Calulate the RGB offsets into the device array for x,y pixel"""
if x > 9:
offset = (x + 80 + y * 3) * 3
else:
offset = (x + y * 10) * 3
return (offset + 2, offset + 1, offset)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

15
PyLeap_CPB_IS31FL3741/code.py Executable file
View file

@ -0,0 +1,15 @@
import board
from rainbowio import colorwheel
from adafruit_is31fl3741.adafruit_ledglasses import LED_Glasses
import adafruit_is31fl3741
glasses = LED_Glasses(board.I2C(), allocate=adafruit_is31fl3741.MUST_BUFFER)
wheeloffset = 0
while True:
for i in range(24):
hue = colorwheel(i * 256 // 24 + wheeloffset)
glasses.right_ring[i] = hue
glasses.left_ring[23 - i] = hue
glasses.show()
wheeloffset += 10