Skip to content

Commit 6c798fe

Browse files
Update the lookup tables for the rgbmatrix5x5.
Update the example for the rgbmatrix5x5. Rename the example for the rgbmatrix5x5 - pylint didn't like the capitals in the name. Tweak some of the other examples to pass pylint.
1 parent 876f835 commit 6c798fe

File tree

4 files changed

+91
-72
lines changed

4 files changed

+91
-72
lines changed

adafruit_is31fl3731/rgbmatrix5x5.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# 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+
26
#
37
# SPDX-License-Identifier: MIT
48

@@ -9,7 +13,7 @@
913
CircuitPython driver for the IS31FL3731 charlieplex IC.
1014
1115
12-
* Author(s): Tony DiCola, Melissa LeBlanc-Williams, David Glaude
16+
* Author(s): Tony DiCola, Melissa LeBlanc-Williams, David Glaude, James Carr
1317
1418
Implementation Notes
1519
--------------------
@@ -37,9 +41,8 @@ class RGBmatrix5x5(IS31FL3731):
3741
width = 25
3842
height = 3
3943

40-
# pylint: disable=too-many-arguments
41-
4244
def pixelrgb(self, x, y, r, g, b, blink=None, frame=None):
45+
# pylint: disable=too-many-arguments
4346
"""
4447
Blink or brightness for x, y-pixel
4548
@@ -51,48 +54,40 @@ def pixelrgb(self, x, y, r, g, b, blink=None, frame=None):
5154
:param blink: True to blink
5255
:param frame: the frame to set the pixel
5356
"""
54-
x = (4 * (3 - x)) + y
57+
x += y * 5
5558

56-
super().pixel(x, 0, g, blink, frame)
57-
super().pixel(x, 1, r, blink, frame)
59+
super().pixel(x, 0, r, blink, frame)
60+
super().pixel(x, 1, g, blink, frame)
5861
super().pixel(x, 2, b, blink, frame)
5962

60-
# pylint: disable=inconsistent-return-statements
61-
# pylint: disable=too-many-return-statements
62-
# pylint: disable=too-many-branches
63-
6463
@staticmethod
6564
def pixel_addr(x, y):
66-
# pylint: disable=duplicate-code
6765
lookup = [
6866
(118, 69, 85),
6967
(117, 68, 101),
7068
(116, 84, 100),
7169
(115, 83, 99),
7270
(114, 82, 98),
73-
(113, 81, 97),
74-
(112, 80, 96),
75-
(134, 21, 37),
76-
(133, 20, 36),
7771
(132, 19, 35),
72+
(133, 20, 36),
73+
(134, 21, 37),
74+
(112, 80, 96),
75+
(113, 81, 97),
7876
(131, 18, 34),
7977
(130, 17, 50),
8078
(129, 33, 49),
8179
(128, 32, 48),
8280
(127, 47, 63),
83-
(121, 41, 57),
84-
(122, 25, 58),
85-
(123, 26, 42),
86-
(124, 27, 43),
8781
(125, 28, 44),
82+
(124, 27, 43),
83+
(123, 26, 42),
84+
(122, 25, 58),
85+
(121, 41, 57),
8886
(126, 29, 45),
8987
(15, 95, 111),
9088
(8, 89, 105),
9189
(9, 90, 106),
9290
(10, 91, 107),
93-
(11, 92, 108),
94-
(12, 76, 109),
95-
(13, 77, 93),
9691
]
9792

9893
return lookup[x][y]

examples/is31fl3731_keybow_2040_rainbow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import math
2020
import board
2121

22-
import adafruit_is31fl3731
22+
from adafruit_is31fl3731.keybow2040 import Keybow2040 as Display
2323

2424
# pylint: disable=inconsistent-return-statements
2525
# pylint: disable=too-many-return-statements
@@ -64,7 +64,7 @@ def hsv_to_rgb(hue, sat, val):
6464
i2c = board.I2C()
6565

6666
# Set up 4x4 RGB matrix of Keybow 2040
67-
display = adafruit_is31fl3731.Keybow2040(i2c)
67+
display = Display(i2c)
6868

6969
step = 0
7070

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: 70 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2021 Sandy Macdonald, David Glaude
1+
# SPDX-FileCopyrightText: 2021 Sandy Macdonald, David Glaude, James Carr
22
# SPDX-License-Identifier: MIT
33

44
"""
@@ -10,22 +10,19 @@
1010
1111
This example is for use on the Pico Explorer Base or other board that use the same SDA/SCL pin.
1212
13-
Author(s): Sandy Macdonald, David Glaude.
13+
Author(s): Sandy Macdonald, David Glaude, James Carr
1414
"""
1515

1616
import time
1717
import math
1818
import busio
1919
import board
2020

21-
from adafruit_is31fl3731.RGBmatrix5x5 import RGBmatrix5x5 as Display
22-
23-
# pylint: disable=inconsistent-return-statements
24-
# pylint: disable=too-many-return-statements
25-
# pylint: disable=invalid-name
21+
from adafruit_is31fl3731.rgbmatrix5x5 import RGBmatrix5x5 as Display
2622

2723

2824
def hsv_to_rgb(hue, sat, val):
25+
# pylint: disable=too-many-return-statements
2926
"""
3027
Convert HSV colour to RGB
3128
@@ -35,7 +32,7 @@ def hsv_to_rgb(hue, sat, val):
3532
"""
3633

3734
if sat == 0.0:
38-
return (val, val, val)
35+
return val, val, val
3936

4037
i = int(hue * 6.0)
4138

@@ -47,61 +44,91 @@ def hsv_to_rgb(hue, sat, val):
4744
i %= 6
4845

4946
if i == 0:
50-
return (val, t, p)
47+
return val, t, p
5148
if i == 1:
52-
return (q, val, p)
49+
return q, val, p
5350
if i == 2:
54-
return (p, val, t)
51+
return p, val, t
5552
if i == 3:
56-
return (p, q, val)
53+
return p, q, val
5754
if i == 4:
58-
return (t, p, val)
55+
return t, p, val
5956
if i == 5:
60-
return (val, p, q)
57+
return val, p, q
58+
59+
# Will never reach here but it keeps pylint happier
60+
return val, val, val
6161

6262

6363
# Create the I2C bus on a Pico Explorer Base
64-
i2c = busio.I2C(board.GP21, board.GP20)
64+
i2c = busio.I2C(board.GP5, board.GP4)
6565

6666
# Set up 5x5 RGB matrix Breakout
6767
display = Display(i2c)
6868

69-
for y in range(0, 5):
70-
for x in range(0, 5):
71-
display.pixelrgb(x, y, 255, 0, 0)
72-
time.sleep(0.1)
7369

74-
time.sleep(0.5)
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)
7577

76-
for y in range(0, 5):
77-
for x in range(0, 5):
78-
display.pixelrgb(x, y, 0, 255, 0)
79-
time.sleep(0.1)
8078

81-
time.sleep(0.5)
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)
8286

83-
for y in range(0, 5):
87+
88+
def test_columns(r, g, b):
89+
# Draw full columns from left to right
8490
for x in range(0, 5):
85-
display.pixelrgb(x, y, 0, 0, 255)
86-
time.sleep(0.1)
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)
8795

88-
time.sleep(0.5)
8996

90-
step = 0
97+
def test_rainbow_sweep():
98+
step = 0
9199

92-
while True:
93-
step += 1
94-
for y in range(0, 5):
95-
for x in range(0, 5):
96-
pixel_hue = (x + y + (step / 20)) / 8
97-
pixel_hue = pixel_hue - int(pixel_hue)
98-
pixel_hue += 0
99-
pixel_hue = pixel_hue - math.floor(pixel_hue)
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)
100107

101-
rgb = hsv_to_rgb(pixel_hue, 1, 1)
108+
rgb = hsv_to_rgb(pixel_hue, 1, 1)
102109

103-
display.pixelrgb(
104-
x, y, int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255)
105-
)
110+
display.pixelrgb(
111+
x, y, int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255)
112+
)
106113

107-
time.sleep(0.01)
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)