Skip to content

Commit 0aebf5c

Browse files
authored
Merge pull request #45 from lesamouraipourpre/matrix5x5
Support Pimoroni RGB Matrix 5x5
2 parents 29a6d20 + cba39c1 commit 0aebf5c

8 files changed

+252
-11
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ repos:
2828
hooks:
2929
- id: pylint_examples
3030
name: pylint (examples code)
31+
require_serial: true
3132
description: Run pylint rules on "examples/*.py" files
3233
entry: /usr/bin/env bash -c
3334
args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)']

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This driver supports the following hardware:
2323
* `Pimoroni 17x7 Scroll pHAT HD <https://www.adafruit.com/product/3473>`_
2424
* `Pimoroni 28x3 (r,g,b) Led Shim <https://www.adafruit.com/product/3831>`_
2525
* `Pimoroni Keybow 2040 with 4x4 matrix of RGB LEDs <https://shop.pimoroni.com/products/keybow-2040>`_
26+
* `Pimoroni 5x5 RGB Matrix Breakout <https://shop.pimoroni.com/products/5x5-rgb-matrix-breakout>`_
2627

2728

2829
Dependencies

adafruit_is31fl3731/keybow2040.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: MIT
44

55
"""
6-
`adafruit_is31fl3731.charlie_bonnet`
6+
`adafruit_is31fl3731.keybow2040`
77
====================================================
88
99
CircuitPython driver for the IS31FL3731 charlieplex IC.

adafruit_is31fl3731/rgbmatrix5x5.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries
2+
# SPDX-FileCopyrightText: Melissa LeBlanc-Williams 2021 for Adafruit Industries
3+
# SPDX-FileCopyrightText: David Glaude 2021
4+
# SPDX-FileCopyrightText: James Carr 2021
5+
6+
#
7+
# SPDX-License-Identifier: MIT
8+
9+
"""
10+
`adafruit_is31fl3731.rgbmatrix5x5`
11+
====================================================
12+
13+
CircuitPython driver for the IS31FL3731 charlieplex IC.
14+
15+
16+
* Author(s): Tony DiCola, Melissa LeBlanc-Williams, David Glaude, James Carr
17+
18+
Implementation Notes
19+
--------------------
20+
21+
**Hardware:**
22+
23+
* `5x5 RGB Matrix Breakout
24+
<https://shop.pimoroni.com/products/5x5-rgb-matrix-breakout>`_
25+
26+
27+
**Software and Dependencies:**
28+
29+
* Adafruit CircuitPython firmware for the supported boards:
30+
https://github.com/adafruit/circuitpython/releases
31+
32+
"""
33+
34+
# imports
35+
from . import IS31FL3731
36+
37+
38+
class RGBmatrix5x5(IS31FL3731):
39+
"""Supports the Pimoroni RGBmatrix5x5 with 5x5 matrix of RGB LEDs """
40+
41+
width = 25
42+
height = 3
43+
44+
def pixelrgb(self, x, y, r, g, b, blink=None, frame=None):
45+
# pylint: disable=too-many-arguments
46+
"""
47+
Blink or brightness for x, y-pixel
48+
49+
:param x: horizontal pixel position
50+
:param y: vertical pixel position
51+
:param r: red brightness value 0->255
52+
:param g: green brightness value 0->255
53+
:param b: blue brightness value 0->255
54+
:param blink: True to blink
55+
:param frame: the frame to set the pixel
56+
"""
57+
x += y * 5
58+
59+
super().pixel(x, 0, r, blink, frame)
60+
super().pixel(x, 1, g, blink, frame)
61+
super().pixel(x, 2, b, blink, frame)
62+
63+
@staticmethod
64+
def pixel_addr(x, y):
65+
lookup = [
66+
(118, 69, 85),
67+
(117, 68, 101),
68+
(116, 84, 100),
69+
(115, 83, 99),
70+
(114, 82, 98),
71+
(132, 19, 35),
72+
(133, 20, 36),
73+
(134, 21, 37),
74+
(112, 80, 96),
75+
(113, 81, 97),
76+
(131, 18, 34),
77+
(130, 17, 50),
78+
(129, 33, 49),
79+
(128, 32, 48),
80+
(127, 47, 63),
81+
(125, 28, 44),
82+
(124, 27, 43),
83+
(123, 26, 42),
84+
(122, 25, 58),
85+
(121, 41, 57),
86+
(126, 29, 45),
87+
(15, 95, 111),
88+
(8, 89, 105),
89+
(9, 90, 106),
90+
(10, 91, 107),
91+
]
92+
93+
return lookup[x][y]

docs/api.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,20 @@
1010
.. automodule:: adafruit_is31fl3731.charlie_wing
1111
:members:
1212

13+
.. automodule:: adafruit_is31fl3731.keybow2040
14+
:members:
15+
16+
.. automodule:: adafruit_is31fl3731.led_shim
17+
:members:
18+
1319
.. automodule:: adafruit_is31fl3731.matrix
1420
:members:
1521

16-
.. automodule:: adafruit_is31fl3731.scroll_phat_hd
22+
.. automodule:: adafruit_is31fl3731.matrix_11x7
1723
:members:
1824

19-
.. automodule:: adafruit_is31fl3731.led_shim
25+
.. automodule:: adafruit_is31fl3731.rgbmatrix5x5
26+
:members:
27+
28+
.. automodule:: adafruit_is31fl3731.scroll_phat_hd
2029
:members:

docs/examples.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@ libraries. CircuitPython does not support PIL/pillow (python imaging library)!
4747
:caption: examples/is31fl3731_pillow_numbers.py
4848
:linenos:
4949

50-
Led Shim Example
51-
----------------
50+
Colorful Examples
51+
-----------------
5252

53-
Example that work on the RGB Led Shim.
53+
Example that works on the RGB Led Shim.
5454

5555
.. literalinclude:: ../examples/is31fl3731_ledshim_rainbow.py
5656
:caption: examples/is31fl3731_ledshim_rainbow.py
5757
:linenos:
58+
59+
Example that works on the RGB Matrix 5x5.
60+
61+
.. literalinclude:: ../examples/is31fl3731_rgbmatrix5x5_rainbow.py
62+
:caption: examples/is31fl3731_rgbmatrix5x5_rainbow.py
63+
:linenos:

examples/is31fl3731_pillow_animated_gif.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,10 @@
5757
loops = 1
5858

5959
# IS31FL3731 only supports 0-7
60-
if loops > 7:
61-
loops = 7
60+
loops = min(loops, 7)
6261

6362
# Get the frame count (maximum 8 frames)
64-
frame_count = image.n_frames
65-
if frame_count > 8:
66-
frame_count = 8
63+
frame_count = min(image.n_frames, 8)
6764

6865
# Load each frame of the gif onto the Matrix
6966
for frame in range(frame_count):
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# SPDX-FileCopyrightText: 2021 Sandy Macdonald, David Glaude, James Carr
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
Example to display a rainbow animation on the 5x5 RGB Matrix Breakout.
6+
7+
Usage:
8+
Rename this file code.py and pop it on your Raspberry Pico's
9+
CIRCUITPY drive.
10+
11+
This example is for use on the Pico Explorer Base or other board that use the same SDA/SCL pin.
12+
13+
Author(s): Sandy Macdonald, David Glaude, James Carr
14+
"""
15+
16+
import time
17+
import math
18+
import busio
19+
import board
20+
21+
from adafruit_is31fl3731.rgbmatrix5x5 import RGBmatrix5x5 as Display
22+
23+
24+
def hsv_to_rgb(hue, sat, val):
25+
# pylint: disable=too-many-return-statements
26+
"""
27+
Convert HSV colour to RGB
28+
29+
:param hue: hue; 0.0-1.0
30+
:param sat: saturation; 0.0-1.0
31+
:param val: value; 0.0-1.0
32+
"""
33+
34+
if sat == 0.0:
35+
return val, val, val
36+
37+
i = int(hue * 6.0)
38+
39+
p = val * (1.0 - sat)
40+
f = (hue * 6.0) - i
41+
q = val * (1.0 - sat * f)
42+
t = val * (1.0 - sat * (1.0 - f))
43+
44+
i %= 6
45+
46+
if i == 0:
47+
return val, t, p
48+
if i == 1:
49+
return q, val, p
50+
if i == 2:
51+
return p, val, t
52+
if i == 3:
53+
return p, q, val
54+
if i == 4:
55+
return t, p, val
56+
if i == 5:
57+
return val, p, q
58+
59+
# Will never reach here but it keeps pylint happier
60+
return val, val, val
61+
62+
63+
# Create the I2C bus on a Pico Explorer Base
64+
i2c = busio.I2C(board.GP5, board.GP4)
65+
66+
# Set up 5x5 RGB matrix Breakout
67+
display = Display(i2c)
68+
69+
70+
def test_pixels(r, g, b):
71+
# Draw each row from left to right, top to bottom
72+
for y in range(0, 5):
73+
for x in range(0, 5):
74+
display.fill(0) # Clear display
75+
display.pixelrgb(x, y, r, g, b)
76+
time.sleep(0.05)
77+
78+
79+
def test_rows(r, g, b):
80+
# Draw full rows from top to bottom
81+
for y in range(0, 5):
82+
display.fill(0) # Clear display
83+
for x in range(0, 5):
84+
display.pixelrgb(x, y, r, g, b)
85+
time.sleep(0.2)
86+
87+
88+
def test_columns(r, g, b):
89+
# Draw full columns from left to right
90+
for x in range(0, 5):
91+
display.fill(0) # Clear display
92+
for y in range(0, 5):
93+
display.pixelrgb(x, y, r, g, b)
94+
time.sleep(0.2)
95+
96+
97+
def test_rainbow_sweep():
98+
step = 0
99+
100+
for _ in range(100):
101+
for y in range(0, 5):
102+
for x in range(0, 5):
103+
pixel_hue = (x + y + (step / 20)) / 8
104+
pixel_hue = pixel_hue - int(pixel_hue)
105+
pixel_hue += 0
106+
pixel_hue = pixel_hue - math.floor(pixel_hue)
107+
108+
rgb = hsv_to_rgb(pixel_hue, 1, 1)
109+
110+
display.pixelrgb(
111+
x, y, int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255)
112+
)
113+
114+
time.sleep(0.01)
115+
step += 3
116+
117+
118+
while True:
119+
test_pixels(64, 0, 0) # RED
120+
test_pixels(0, 64, 0) # GREEN
121+
test_pixels(0, 0, 64) # BLUE
122+
test_pixels(64, 64, 64) # WHITE
123+
124+
test_rows(64, 0, 0) # RED
125+
test_rows(0, 64, 0) # GREEN
126+
test_rows(0, 0, 64) # BLUE
127+
test_rows(64, 64, 64) # WHITE
128+
129+
test_columns(64, 0, 0) # RED
130+
test_columns(0, 64, 0) # GREEN
131+
test_columns(0, 0, 64) # BLUE
132+
test_columns(64, 64, 64) # WHITE
133+
134+
test_rainbow_sweep()

0 commit comments

Comments
 (0)