Skip to content

Commit 68711b9

Browse files
authored
Merge pull request #26 from dglaude/master
Add LED SHIM from Pimoroni support
2 parents a640e19 + 86699cd commit 68711b9

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ This driver supports the following hardware:
2121
* `Adafruit 15x7 CharliePlex LED Matrix Display FeatherWings <https://www.adafruit.com/product/2965>`_
2222
* `Adafruit 16x8 CharliePlex LED Matrix Bonnets <https://www.adafruit.com/product/4127>`_
2323
* `Pimoroni 17x7 Scroll pHAT HD <https://www.adafruit.com/product/3473>`_
24+
* `Pimoroni 28x3 (r,g,b) Led Shim <https://www.adafruit.com/product/3831>`_
25+
2426

2527
Dependencies
2628
=============

adafruit_is31fl3731.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,90 @@ def pixel_addr(x, y):
413413
x = x - 8
414414
y = y - 8
415415
return x * 16 + y
416+
417+
418+
class LedShim(Matrix):
419+
"""Supports the LED SHIM by Pimoroni"""
420+
421+
width = 28
422+
height = 3
423+
424+
425+
def __init__(self, i2c, address=0x75):
426+
super().__init__(i2c, address)
427+
428+
429+
# pylint: disable-msg=too-many-arguments
430+
def pixelrgb(self, x, r, g, b, blink=None, frame=None):
431+
"""
432+
Blink or brightness for x-pixel
433+
434+
:param x: horizontal pixel position
435+
:param r: red brightness value 0->255
436+
:param g: green brightness value 0->255
437+
:param b: blue brightness value 0->255
438+
:param blink: True to blink
439+
:param frame: the frame to set the pixel
440+
"""
441+
super().pixel(x, 0, r, blink, frame)
442+
super().pixel(x, 1, g, blink, frame)
443+
super().pixel(x, 2, b, blink, frame)
444+
445+
446+
# pylint: disable=inconsistent-return-statements
447+
# pylint: disable=too-many-return-statements
448+
# pylint: disable=too-many-branches
449+
@staticmethod
450+
def pixel_addr(x, y):
451+
"""Translate an x,y coordinate to a pixel index."""
452+
if y == 0:
453+
if x < 7:
454+
return 118 - x
455+
if x < 15:
456+
return 141 - x
457+
if x < 21:
458+
return 106 + x
459+
if x == 21:
460+
return 15
461+
return x - 14
462+
463+
if y == 1:
464+
if x < 2:
465+
return 69 - x
466+
if x < 7:
467+
return 86 - x
468+
if x < 12:
469+
return 28 - x
470+
if x < 14:
471+
return 45 - x
472+
if x == 14:
473+
return 47
474+
if x == 15:
475+
return 41
476+
if x < 21:
477+
return x + 9
478+
if x == 21:
479+
return 95
480+
if x < 26:
481+
return x + 67
482+
return x + 50
483+
484+
if x == 0:
485+
return 85
486+
if x < 7:
487+
return 102 - x
488+
if x < 11:
489+
return 44 - x
490+
if x < 14:
491+
return 61 - x
492+
if x == 14:
493+
return 63
494+
if x < 17:
495+
return 42 + x
496+
if x < 21:
497+
return x + 25
498+
if x == 21:
499+
return 111
500+
if x < 27:
501+
return x + 83
502+
return 93
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import time
2+
import board
3+
import busio
4+
import adafruit_is31fl3731
5+
6+
i2c = busio.I2C(board.SCL, board.SDA)
7+
8+
# initial display if you are using Pimoroni LED SHIM
9+
display = adafruit_is31fl3731.LedShim(i2c)
10+
11+
# This list 28 colors from a rainbow...
12+
rainbow=[
13+
(255, 0, 0) , (255, 54, 0) , (255, 109, 0) , (255, 163, 0) ,
14+
(255, 218, 0) , (236, 255, 0) , (182, 255, 0) , (127, 255, 0) ,
15+
(72, 255, 0) , (18, 255, 0) , (0, 255, 36) , (0, 255, 91) ,
16+
(0, 255, 145) , (0, 255, 200) , (0, 255, 255) , (0, 200, 255) ,
17+
(0, 145, 255) , (0, 91, 255) , (0, 36, 255) , (18, 0, 255) ,
18+
(72, 0, 255) , (127, 0, 255) , (182, 0, 255) , (236, 0, 255) ,
19+
(255, 0, 218) , (255, 0, 163) , (255, 0, 109) , (255, 0, 54)]
20+
21+
22+
for y in range(3):
23+
for x in range(28):
24+
display.pixel(x, y, 255)
25+
time.sleep(0.1)
26+
display.pixel(x, y, 0)
27+
28+
while True:
29+
for offset in range(28):
30+
for x in range(28):
31+
r,g,b = rainbow[(x+offset)%28]
32+
display.pixelrgb(x, r, g, b)

0 commit comments

Comments
 (0)