Skip to content

Add LED SHIM from Pimoroni support #26

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 11 commits into from
Apr 6, 2020
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ This driver supports the following hardware:
* `Adafruit 15x7 CharliePlex LED Matrix Display FeatherWings <https://www.adafruit.com/product/2965>`_
* `Adafruit 16x8 CharliePlex LED Matrix Bonnets <https://www.adafruit.com/product/4127>`_
* `Pimoroni 17x7 Scroll pHAT HD <https://www.adafruit.com/product/3473>`_
* `Pimoroni 28x3 (r,g,b) Led Shim <https://www.adafruit.com/product/3831>`_


Dependencies
=============
Expand Down
87 changes: 87 additions & 0 deletions adafruit_is31fl3731.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,90 @@ def pixel_addr(x, y):
x = x - 8
y = y - 8
return x * 16 + y


class LedShim(Matrix):
"""Supports the LED SHIM by Pimoroni"""

width = 28
height = 3


def __init__(self, i2c, address=0x75):
super().__init__(i2c, address)


# pylint: disable-msg=too-many-arguments
def pixelrgb(self, x, r, g, b, blink=None, frame=None):
"""
Blink or brightness for x-pixel

:param x: horizontal pixel position
:param r: red brightness value 0->255
:param g: green brightness value 0->255
:param b: blue brightness value 0->255
:param blink: True to blink
:param frame: the frame to set the pixel
"""
super().pixel(x, 0, r, blink, frame)
super().pixel(x, 1, g, blink, frame)
super().pixel(x, 2, b, blink, frame)


# pylint: disable=inconsistent-return-statements
# pylint: disable=too-many-return-statements
# pylint: disable=too-many-branches
@staticmethod
def pixel_addr(x, y):
"""Translate an x,y coordinate to a pixel index."""
if y == 0:
if x < 7:
return 118 - x
if x < 15:
return 141 - x
if x < 21:
return 106 + x
if x == 21:
return 15
return x - 14

if y == 1:
if x < 2:
return 69 - x
if x < 7:
return 86 - x
if x < 12:
return 28 - x
if x < 14:
return 45 - x
if x == 14:
return 47
if x == 15:
return 41
if x < 21:
return x + 9
if x == 21:
return 95
if x < 26:
return x + 67
return x + 50

if x == 0:
return 85
if x < 7:
return 102 - x
if x < 11:
return 44 - x
if x < 14:
return 61 - x
if x == 14:
return 63
if x < 17:
return 42 + x
if x < 21:
return x + 25
if x == 21:
return 111
if x < 27:
return x + 83
return 93
32 changes: 32 additions & 0 deletions examples/is31fl3731_ledshim_rainbow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import time
import board
import busio
import adafruit_is31fl3731

i2c = busio.I2C(board.SCL, board.SDA)

# initial display if you are using Pimoroni LED SHIM
display = adafruit_is31fl3731.LedShim(i2c)

# This list 28 colors from a rainbow...
rainbow=[
(255, 0, 0) , (255, 54, 0) , (255, 109, 0) , (255, 163, 0) ,
(255, 218, 0) , (236, 255, 0) , (182, 255, 0) , (127, 255, 0) ,
(72, 255, 0) , (18, 255, 0) , (0, 255, 36) , (0, 255, 91) ,
(0, 255, 145) , (0, 255, 200) , (0, 255, 255) , (0, 200, 255) ,
(0, 145, 255) , (0, 91, 255) , (0, 36, 255) , (18, 0, 255) ,
(72, 0, 255) , (127, 0, 255) , (182, 0, 255) , (236, 0, 255) ,
(255, 0, 218) , (255, 0, 163) , (255, 0, 109) , (255, 0, 54)]


for y in range(3):
for x in range(28):
display.pixel(x, y, 255)
time.sleep(0.1)
display.pixel(x, y, 0)

while True:
for offset in range(28):
for x in range(28):
r,g,b = rainbow[(x+offset)%28]
display.pixelrgb(x, r, g, b)