From 4bbfc98f559e328092ba30805dc6e88ccb1e8a2e Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 5 Apr 2020 16:34:33 +0200 Subject: [PATCH 01/10] Add support and exemple for Led Shim 28 RGB by Pimoroni --- README.rst | 2 + adafruit_is31fl3731.py | 65 ++++++++++++++++++++++++++ examples/is31fl3731_ledshim_rainbow.py | 55 ++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 examples/is31fl3731_ledshim_rainbow.py diff --git a/README.rst b/README.rst index 6bb86a5..497ba4a 100644 --- a/README.rst +++ b/README.rst @@ -21,6 +21,8 @@ This driver supports the following hardware: * `Adafruit 15x7 CharliePlex LED Matrix Display FeatherWings `_ * `Adafruit 16x8 CharliePlex LED Matrix Bonnets `_ * `Pimoroni 17x7 Scroll pHAT HD `_ +* `Pimoroni 28x3 (r,g,b) Led Shim `_ + Dependencies ============= diff --git a/adafruit_is31fl3731.py b/adafruit_is31fl3731.py index 63894ab..be56e77 100644 --- a/adafruit_is31fl3731.py +++ b/adafruit_is31fl3731.py @@ -413,3 +413,68 @@ 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) + + + + @staticmethod + def pixel_addr(x, y): + """Translate an x,y coordinate to a pixel index.""" + lookup = [ + (118, 69, 85), + (117, 68, 101), + (116, 84, 100), + (115, 83, 99), + (114, 82, 98), + (113, 81, 97), + (112, 80, 96), + (134, 21, 37), + (133, 20, 36), + (132, 19, 35), + (131, 18, 34), + (130, 17, 50), + (129, 33, 49), + (128, 32, 48), + (127, 47, 63), + (121, 41, 57), + (122, 25, 58), + (123, 26, 42), + (124, 27, 43), + (125, 28, 44), + (126, 29, 45), + (15, 95, 111), + (8, 89, 105), + (9, 90, 106), + (10, 91, 107), + (11, 92, 108), + (12, 76, 109), + (13, 77, 93), + ] + return lookup[x][y] \ No newline at end of file diff --git a/examples/is31fl3731_ledshim_rainbow.py b/examples/is31fl3731_ledshim_rainbow.py new file mode 100644 index 0000000..59de24d --- /dev/null +++ b/examples/is31fl3731_ledshim_rainbow.py @@ -0,0 +1,55 @@ +import board +import busio +import adafruit_is31fl3731 +import time + +i2c = busio.I2C(board.SCL, board.SDA) + +# initialize display using Feather CharlieWing LED 15 x 7 +#display = adafruit_is31fl3731.CharlieBonnet(i2c, address=0x75) + +# uncomment next line if you are using Pimoroni LED SHIM +#display = adafruit_is31fl3731.LedShim(i2c, address=0x75) +display = adafruit_is31fl3731.LedShim(i2c) + +# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet +# display = adafruit_is31fl3731.CharlieBonnet(i2c) + +# initial display using Pimoroni Scroll Phat HD LED 17 x 7 +# display = adafruit_is31fl3731.ScrollPhatHD(i2c) + +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)] + +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) \ No newline at end of file From 911a8d47794c8b536a34145d6daefee58eb7371b Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 5 Apr 2020 17:41:58 +0200 Subject: [PATCH 02/10] Simplify the example, more readable --- examples/is31fl3731_ledshim_rainbow.py | 50 +++++--------------------- 1 file changed, 9 insertions(+), 41 deletions(-) diff --git a/examples/is31fl3731_ledshim_rainbow.py b/examples/is31fl3731_ledshim_rainbow.py index 59de24d..11197e8 100644 --- a/examples/is31fl3731_ledshim_rainbow.py +++ b/examples/is31fl3731_ledshim_rainbow.py @@ -1,55 +1,23 @@ import board import busio import adafruit_is31fl3731 -import time i2c = busio.I2C(board.SCL, board.SDA) -# initialize display using Feather CharlieWing LED 15 x 7 -#display = adafruit_is31fl3731.CharlieBonnet(i2c, address=0x75) - -# uncomment next line if you are using Pimoroni LED SHIM -#display = adafruit_is31fl3731.LedShim(i2c, address=0x75) +# initial display if you are using Pimoroni LED SHIM display = adafruit_is31fl3731.LedShim(i2c) -# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet -# display = adafruit_is31fl3731.CharlieBonnet(i2c) - -# initial display using Pimoroni Scroll Phat HD LED 17 x 7 -# display = adafruit_is31fl3731.ScrollPhatHD(i2c) - 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)] + (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)] 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) \ No newline at end of file + display.pixelrgb(x, r, g, b) From ee70411764ce7b7a740d92546c642827af2bb155 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 5 Apr 2020 17:58:25 +0200 Subject: [PATCH 03/10] Make PyLint happy? --- adafruit_is31fl3731.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_is31fl3731.py b/adafruit_is31fl3731.py index be56e77..8e90959 100644 --- a/adafruit_is31fl3731.py +++ b/adafruit_is31fl3731.py @@ -477,4 +477,4 @@ def pixel_addr(x, y): (12, 76, 109), (13, 77, 93), ] - return lookup[x][y] \ No newline at end of file + return lookup[x][y] From ca5d4875beccb794d4f53d8b3b9a9d6f3a826daf Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 5 Apr 2020 20:15:45 +0200 Subject: [PATCH 04/10] Use math rather than table and expanded demo code --- adafruit_is31fl3731.py | 84 ++++++++++++++++---------- examples/is31fl3731_ledshim_rainbow.py | 10 ++- 2 files changed, 62 insertions(+), 32 deletions(-) diff --git a/adafruit_is31fl3731.py b/adafruit_is31fl3731.py index be56e77..41b99d9 100644 --- a/adafruit_is31fl3731.py +++ b/adafruit_is31fl3731.py @@ -447,34 +447,56 @@ def pixelrgb(self, x, r, g, b, blink=None, frame=None): @staticmethod def pixel_addr(x, y): """Translate an x,y coordinate to a pixel index.""" - lookup = [ - (118, 69, 85), - (117, 68, 101), - (116, 84, 100), - (115, 83, 99), - (114, 82, 98), - (113, 81, 97), - (112, 80, 96), - (134, 21, 37), - (133, 20, 36), - (132, 19, 35), - (131, 18, 34), - (130, 17, 50), - (129, 33, 49), - (128, 32, 48), - (127, 47, 63), - (121, 41, 57), - (122, 25, 58), - (123, 26, 42), - (124, 27, 43), - (125, 28, 44), - (126, 29, 45), - (15, 95, 111), - (8, 89, 105), - (9, 90, 106), - (10, 91, 107), - (11, 92, 108), - (12, 76, 109), - (13, 77, 93), - ] - return lookup[x][y] \ No newline at end of file + if y==0: + if x<7: + return 118 - x + elif x<15: + return 141 - x + elif x<21: + return 106 + x + elif x == 21: + return 15 + else: + return x - 14 + elif y==1: + if x<2: + return 69 - x + elif x<7: + return 86 - x + elif x<12: + return 28 - x + elif x<14: + return 45 - x + elif x == 14: + return 47 + elif x == 15: + return 41 + elif x<21: + return x + 9 + elif x == 21: + return 95 + elif x<26: + return x + 67 + else: + return x + 50 + elif y==2: + if x==0: + return 85 + elif x<7: + return 102 - x + elif x<11: + return 44 - x + elif x<14: + return 61 - x + elif x == 14: + return 63 + elif x < 17: + return 42 + x + elif x<21: + return x + 25 + elif x == 21: + return 111 + elif x<27: + return x + 83 + else: + return 93 \ No newline at end of file diff --git a/examples/is31fl3731_ledshim_rainbow.py b/examples/is31fl3731_ledshim_rainbow.py index 11197e8..53fcf4a 100644 --- a/examples/is31fl3731_ledshim_rainbow.py +++ b/examples/is31fl3731_ledshim_rainbow.py @@ -1,6 +1,7 @@ import board import busio import adafruit_is31fl3731 +import time i2c = busio.I2C(board.SCL, board.SDA) @@ -16,8 +17,15 @@ (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) + display.pixelrgb(x, r, g, b) \ No newline at end of file From 22b854d2682814c6312ed10ae561c5b7fdd501ba Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 5 Apr 2020 20:40:08 +0200 Subject: [PATCH 05/10] Now pylint should be OK --- adafruit_is31fl3731.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adafruit_is31fl3731.py b/adafruit_is31fl3731.py index 63f99f3..a0e88e0 100644 --- a/adafruit_is31fl3731.py +++ b/adafruit_is31fl3731.py @@ -481,7 +481,7 @@ def pixel_addr(x, y): return x + 67 else: return x + 50 - elif y == 2: + else: if x == 0: return 85 elif x < 7: @@ -502,4 +502,3 @@ def pixel_addr(x, y): return x + 83 else: return 93 - From 76a8e63031b1e65cf4987d5893f257a8819a8f18 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 5 Apr 2020 21:25:22 +0200 Subject: [PATCH 06/10] Explain the rainbow table --- examples/is31fl3731_ledshim_rainbow.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/is31fl3731_ledshim_rainbow.py b/examples/is31fl3731_ledshim_rainbow.py index 53fcf4a..469e4b4 100644 --- a/examples/is31fl3731_ledshim_rainbow.py +++ b/examples/is31fl3731_ledshim_rainbow.py @@ -8,6 +8,7 @@ # 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) , @@ -28,4 +29,4 @@ for offset in range(28): for x in range(28): r,g,b = rainbow[(x+offset)%28] - display.pixelrgb(x, r, g, b) \ No newline at end of file + display.pixelrgb(x, r, g, b) From bf6b9313552bd5afc3e309fcb0fe332abc894e54 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 5 Apr 2020 21:32:37 +0200 Subject: [PATCH 07/10] no-else-return to make PyLint happy --- adafruit_is31fl3731.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/adafruit_is31fl3731.py b/adafruit_is31fl3731.py index a0e88e0..c8839cb 100644 --- a/adafruit_is31fl3731.py +++ b/adafruit_is31fl3731.py @@ -458,8 +458,7 @@ def pixel_addr(x, y): return 106 + x elif x == 21: return 15 - else: - return x - 14 + return x - 14 elif y == 1: if x < 2: return 69 - x @@ -479,8 +478,7 @@ def pixel_addr(x, y): return 95 elif x < 26: return x + 67 - else: - return x + 50 + return x + 50 else: if x == 0: return 85 @@ -500,5 +498,4 @@ def pixel_addr(x, y): return 111 elif x < 27: return x + 83 - else: - return 93 + return 93 From 415b034999f8416fb752616d7eb53b41df519944 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 5 Apr 2020 21:39:48 +0200 Subject: [PATCH 08/10] I hate PyLint and so should you... --- adafruit_is31fl3731.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/adafruit_is31fl3731.py b/adafruit_is31fl3731.py index c8839cb..383c597 100644 --- a/adafruit_is31fl3731.py +++ b/adafruit_is31fl3731.py @@ -459,7 +459,7 @@ def pixel_addr(x, y): elif x == 21: return 15 return x - 14 - elif y == 1: + if y == 1: if x < 2: return 69 - x elif x < 7: @@ -479,23 +479,23 @@ def pixel_addr(x, y): elif x < 26: return x + 67 return x + 50 - else: - if x == 0: - return 85 - elif x < 7: - return 102 - x - elif x < 11: - return 44 - x - elif x < 14: - return 61 - x - elif x == 14: - return 63 - elif x < 17: - return 42 + x - elif x < 21: - return x + 25 - elif x == 21: - return 111 - elif x < 27: - return x + 83 - return 93 + + if x == 0: + return 85 + elif x < 7: + return 102 - x + elif x < 11: + return 44 - x + elif x < 14: + return 61 - x + elif x == 14: + return 63 + elif x < 17: + return 42 + x + elif x < 21: + return x + 25 + elif x == 21: + return 111 + elif x < 27: + return x + 83 + return 93 From ef4eab9a28ed2decbcc4899158a630752711d742 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 5 Apr 2020 21:46:35 +0200 Subject: [PATCH 09/10] No more elif --- adafruit_is31fl3731.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/adafruit_is31fl3731.py b/adafruit_is31fl3731.py index 383c597..4492c8d 100644 --- a/adafruit_is31fl3731.py +++ b/adafruit_is31fl3731.py @@ -452,50 +452,51 @@ def pixel_addr(x, y): if y == 0: if x < 7: return 118 - x - elif x < 15: + if x < 15: return 141 - x - elif x < 21: + if x < 21: return 106 + x - elif x == 21: + if x == 21: return 15 return x - 14 + if y == 1: if x < 2: return 69 - x - elif x < 7: + if x < 7: return 86 - x - elif x < 12: + if x < 12: return 28 - x - elif x < 14: + if x < 14: return 45 - x - elif x == 14: + if x == 14: return 47 - elif x == 15: + if x == 15: return 41 - elif x < 21: + if x < 21: return x + 9 - elif x == 21: + if x == 21: return 95 - elif x < 26: + if x < 26: return x + 67 return x + 50 if x == 0: return 85 - elif x < 7: + if x < 7: return 102 - x - elif x < 11: + if x < 11: return 44 - x - elif x < 14: + if x < 14: return 61 - x - elif x == 14: + if x == 14: return 63 - elif x < 17: + if x < 17: return 42 + x - elif x < 21: + if x < 21: return x + 25 - elif x == 21: + if x == 21: return 111 - elif x < 27: + if x < 27: return x + 83 return 93 From 86699cd22e6d41a2642974e0b0f7da734f766ad5 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 5 Apr 2020 21:50:26 +0200 Subject: [PATCH 10/10] import time first --- examples/is31fl3731_ledshim_rainbow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/is31fl3731_ledshim_rainbow.py b/examples/is31fl3731_ledshim_rainbow.py index 469e4b4..d4ef8ba 100644 --- a/examples/is31fl3731_ledshim_rainbow.py +++ b/examples/is31fl3731_ledshim_rainbow.py @@ -1,7 +1,7 @@ +import time import board import busio import adafruit_is31fl3731 -import time i2c = busio.I2C(board.SCL, board.SDA)