Skip to content

Commit c1166f0

Browse files
committed
make library lowercase + remove the matrix singularity + adapt example
1 parent d85fd57 commit c1166f0

15 files changed

+113
-102
lines changed

adafruit_is31fl3731/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@
7878
_COLOR_OFFSET = const(0x24)
7979

8080

81-
class Matrix:
81+
class IS31FL3731:
8282
"""
83-
The Matrix class support the main function for driving the 16x9 matrix Display
83+
The IS31FL3731 is an abstract class contain the main function related to this chip.
84+
Each board needs to define width, height and pixel_addr.
8485
8586
:param ~adafruit_bus_device.i2c_device i2c_device: the connected i2c bus i2c_device
8687
:param address: the device address; defaults to 0x74
@@ -298,6 +299,7 @@ def fill(self, color=None, blink=None, frame=None):
298299
for col in range(18):
299300
self._register(frame, _BLINK_OFFSET + col, data)
300301

302+
# This function must be replaced for each board
301303
@staticmethod
302304
def pixel_addr(x, y):
303305
"""Calulate the offset into the device array for x,y pixel

adafruit_is31fl3731/CharlieBonnet.py renamed to adafruit_is31fl3731/charlie_bonnet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
"""
4848

4949
# imports
50-
from . import Matrix
50+
from . import IS31FL3731
5151

5252

53-
class CharlieBonnet(Matrix):
53+
class CharlieBonnet(IS31FL3731):
5454
"""Supports the Charlieplexed bonnet"""
5555

5656
width = 16

adafruit_is31fl3731/CharlieWing.py renamed to adafruit_is31fl3731/charlie_wing.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
3535
**Hardware:**
3636
37-
* `Adafruit 16x9 Charlieplexed PWM LED Matrix Driver - IS31FL3731
38-
<https://www.adafruit.com/product/2946>`_
39-
4037
* `Adafruit 15x7 CharliePlex LED Matrix Display FeatherWings
4138
<https://www.adafruit.com/product/2965>`_
4239
@@ -47,10 +44,10 @@
4744
"""
4845

4946
# imports
50-
from . import Matrix
47+
from . import IS31FL3731
5148

5249

53-
class CharlieWing(Matrix):
50+
class CharlieWing(IS31FL3731):
5451
"""Supports the Charlieplexed feather wing
5552
"""
5653

adafruit_is31fl3731/LedShim.py renamed to adafruit_is31fl3731/led_shim.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
"""
4545

4646
# imports
47-
from . import Matrix
47+
from . import IS31FL3731
4848

4949

50-
class LedShim(Matrix):
50+
class LedShim(IS31FL3731):
5151
"""Supports the LED SHIM by Pimoroni"""
5252

5353
width = 28

adafruit_is31fl3731/matrix.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2017 Tony DiCola
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
23+
"""
24+
`adafruit_is31fl3731`
25+
====================================================
26+
27+
CircuitPython driver for the IS31FL3731 charlieplex IC.
28+
29+
30+
* Author(s): Tony DiCola, Melissa LeBlanc-Williams
31+
32+
Implementation Notes
33+
--------------------
34+
35+
**Hardware:**
36+
37+
* `Adafruit 16x9 Charlieplexed PWM LED Matrix Driver - IS31FL3731
38+
<https://www.adafruit.com/product/2946>`_
39+
40+
**Software and Dependencies:**
41+
42+
* Adafruit CircuitPython firmware (2.2.0+) for the ESP8622 and M0-based boards:
43+
https://github.com/adafruit/circuitpython/releases
44+
"""
45+
46+
# imports
47+
from . import IS31FL3731
48+
49+
50+
class Matrix(IS31FL3731):
51+
"""Supports the Charlieplexed feather wing
52+
"""
53+
54+
width = 16
55+
height = 9
56+
57+
@staticmethod
58+
def pixel_addr(x, y):
59+
"""Calulate the offset into the device array for x,y pixel
60+
"""
61+
return x + y * 16

adafruit_is31fl3731/ScrollPhatHD.py renamed to adafruit_is31fl3731/scroll_phat_hd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
"""
4545

4646
# imports
47-
from . import Matrix
47+
from . import IS31FL3731
4848

4949

50-
class ScrollPhatHD(Matrix):
50+
class ScrollPhatHD(IS31FL3731):
5151
"""Supports the Scroll pHAT HD by Pimoroni"""
5252

5353
width = 17

examples/is31fl3731_blink_example.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,21 @@
22
import busio
33

44
# uncomment next line if you are using Feather CharlieWing LED 15 x 7
5-
from adafruit_is31fl3731.CharlieWing import CharlieWing
5+
from adafruit_is31fl3731.charlie_wing import CharlieWing as Display
66

77
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
8-
# from adafruit_is31fl3731 import Matrix
8+
# from adafruit_is31fl3731.matrix import Matrix as Display
99
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
10-
# from adafruit_is31fl3731.CharlieBonnet import CharlieBonnet
10+
# from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display
1111
# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7
12-
# from adafruit_is31fl3731.ScrollPhatHD import ScrollPhatHD
12+
# from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display
1313

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

1616
# array pattern in bits; top row-> bottom row, 8 bits in each row
1717
an_arrow = bytearray((0x08, 0x0C, 0xFE, 0xFF, 0xFE, 0x0C, 0x08, 0x00, 0x00))
1818

19-
# uncomment next line if you are using Feather CharlieWing LED 15 x 7
20-
display = CharlieWing(i2c)
21-
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
22-
# display = Matrix(i2c)
23-
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
24-
# display = CharlieBonnet(i2c)
25-
# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7
26-
# display = ScrollPhatHD(i2c)
19+
display = Display(i2c)
2720

2821
# first load the frame with the arrows; moves the an_arrow to the right in each
2922
# frame

examples/is31fl3731_frame_example.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,21 @@
33
import busio
44

55
# uncomment next line if you are using Feather CharlieWing LED 15 x 7
6-
from adafruit_is31fl3731.CharlieWing import CharlieWing
6+
from adafruit_is31fl3731.charlie_wing import CharlieWing as Display
77

88
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
9-
# from adafruit_is31fl3731 import Matrix
9+
# from adafruit_is31fl3731.matrix import Matrix as Display
1010
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
11-
# from adafruit_is31fl3731.CharlieBonnet import CharlieBonnet
11+
# from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display
1212
# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7
13-
# from adafruit_is31fl3731.ScrollPhatHD import ScrollPhatHD
13+
# from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display
1414

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

1717
# arrow pattern in bits; top row-> bottom row, 8 bits in each row
1818
arrow = bytearray((0x08, 0x0C, 0xFE, 0xFF, 0xFE, 0x0C, 0x08, 0x00, 0x00))
1919

20-
# uncomment next line if you are using Feather CharlieWing LED 15 x 7
21-
display = CharlieWing(i2c)
22-
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
23-
# display = Matrix(i2c)
24-
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
25-
# display = CharlieBonnet(i2c)
26-
# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7
27-
# display = ScrollPhatHD(i2c)
20+
display = Display(i2c)
2821

2922

3023
# first load the frame with the arrows; moves the arrow to the right in each

examples/is31fl3731_ledshim_rainbow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import time
22
import board
33
import busio
4-
from adafruit_is31fl3731.LedShim import LedShim
4+
from adafruit_is31fl3731.led_shim import LedShim as Display
55

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

88
# initial display if you are using Pimoroni LED SHIM
9-
display = LedShim(i2c)
9+
display = Display(i2c)
1010

1111
# This list 28 colors from a rainbow...
1212
rainbow = [

examples/is31fl3731_pillow_animated_gif.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,17 @@
1717
from PIL import Image
1818

1919
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
20-
# from adafruit_is31fl3731 import Matrix
20+
# from adafruit_is31fl3731.matrix import Matrix as Display
2121
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
22-
from adafruit_is31fl3731.CharlieBonnet import CharlieBonnet
22+
from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display
2323

2424
# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7
25-
# from adafruit_is31fl3731.ScrollPhatHD import ScrollPhatHD
25+
# from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display
2626

2727
i2c = board.I2C()
2828

29-
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
30-
# display = Matrix(i2c)
31-
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
32-
display = CharlieBonnet(i2c)
33-
# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7
34-
# display = ScrollPhatHD(i2c)
29+
display = Display(i2c)
30+
3531

3632
# Open the gif
3733
if len(sys.argv) < 2:

examples/is31fl3731_pillow_marquee.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,19 @@
1212
from PIL import Image, ImageDraw, ImageFont
1313

1414
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
15-
# from adafruit_is31fl3731 import Matrix
15+
# from adafruit_is31fl3731.matrix import Matrix as Display
1616
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
17-
from adafruit_is31fl3731.CharlieBonnet import CharlieBonnet
17+
from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display
1818

1919
# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7
20-
# from adafruit_is31fl3731.ScrollPhatHD import ScrollPhatHD
20+
# from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display
2121

2222
SCROLLING_TEXT = "You can display a personal message here..."
2323
BRIGHTNESS = 64 # Brightness can be between 0-255
2424

2525
i2c = board.I2C()
2626

27-
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
28-
# display = Matrix(i2c)
29-
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
30-
display = CharlieBonnet(i2c)
31-
# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7
32-
# display = ScrollPhatHD(i2c)
27+
display = Display(i2c)
3328

3429
# Load a font
3530
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 8)

examples/is31fl3731_pillow_numbers.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,18 @@
1313
from PIL import Image, ImageDraw, ImageFont
1414

1515
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
16-
# from adafruit_is31fl3731 import Matrix
16+
# from adafruit_is31fl3731.matrix import Matrix as Display
1717
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
18-
from adafruit_is31fl3731.CharlieBonnet import CharlieBonnet
18+
from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display
1919

2020
# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7
21-
# from adafruit_is31fl3731.ScrollPhatHD import ScrollPhatHD
21+
# from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display
2222

2323
BRIGHTNESS = 32 # Brightness can be between 0-255
2424

2525
i2c = board.I2C()
2626

27-
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
28-
# display = Matrix(i2c)
29-
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
30-
display = CharlieBonnet(i2c)
31-
# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7
32-
# display = ScrollPhatHD(i2c)
27+
display = Display(i2c)
3328

3429
display.fill(0)
3530

examples/is31fl3731_simpletest.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,18 @@
22
import busio
33

44
# uncomment next line if you are using Feather CharlieWing LED 15 x 7
5-
from adafruit_is31fl3731.CharlieWing import CharlieWing
5+
from adafruit_is31fl3731.charlie_wing import CharlieWing as Display
66

77
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
8-
# from adafruit_is31fl3731 import Matrix
8+
# from adafruit_is31fl3731.matrix import Matrix as Display
99
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
10-
# from adafruit_is31fl3731.CharlieBonnet import CharlieBonnet
10+
# from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display
1111
# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7
12-
# from adafruit_is31fl3731.ScrollPhatHD import ScrollPhatHD
12+
# from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display
1313

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

16-
# uncomment next line if you are using Feather CharlieWing LED 15 x 7
17-
display = CharlieWing(i2c)
18-
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
19-
# display = Matrix(i2c)
20-
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
21-
# display = CharlieBonnet(i2c)
22-
# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7
23-
# display = ScrollPhatHD(i2c)
16+
display = Display(i2c)
2417

2518
# draw a box on the display
2619
# first draw the top and bottom edges

examples/is31fl3731_text_example.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,18 @@
33
import adafruit_framebuf
44

55
# uncomment next line if you are using Feather CharlieWing LED 15 x 7
6-
# from adafruit_is31fl3731.CharlieWing import CharlieWing
6+
# from adafruit_is31fl3731.charliewing import CharlieWing as Display
77
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
8-
# from adafruit_is31fl3731 import Matrix
8+
# from adafruit_is31fl3731.matrix import Matrix as Display
99
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
10-
from adafruit_is31fl3731.CharlieBonnet import CharlieBonnet
10+
from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display
1111

1212
# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7
13-
# from adafruit_is31fl3731.ScrollPhatHD import ScrollPhatHD
13+
# from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display
1414

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

17-
# uncomment next line if you are using Feather CharlieWing LED 15 x 7
18-
# display = CharlieWing(i2c)
19-
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
20-
# display = Matrix(i2c)
21-
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
22-
display = CharlieBonnet(i2c)
23-
# uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7
24-
# display = ScrollPhatHD(i2c)
17+
display = Display(i2c)
2518

2619
text_to_show = "Adafruit!!"
2720

0 commit comments

Comments
 (0)