Skip to content

Commit 4e2266c

Browse files
authored
Merge pull request #49 from makermelissa/matrix_scroll
Refactored Matrix classes. Added additional class for backpack
2 parents 3557734 + 7031387 commit 4e2266c

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

adafruit_ht16k33/matrix.py

100644100755
Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,16 @@
3131
__version__ = "0.0.0-auto.0"
3232
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git"
3333

34-
class Matrix16x8(HT16K33):
35-
"""A double matrix or the matrix wing."""
34+
class Matrix8x8(HT16K33):
35+
"""A single matrix."""
3636
def pixel(self, x, y, color=None):
3737
"""Get or set the color of a given pixel."""
38-
if not 0 <= x <= 15:
38+
if not 0 <= x <= 7:
3939
return None
4040
if not 0 <= y <= 7:
4141
return None
42-
if x >= 8:
43-
x -= 8
44-
y += 8
45-
return super()._pixel(y, x, color)
42+
x = (x - 1) % 8
43+
return super()._pixel(x, y, color)
4644

4745
def __getitem__(self, key):
4846
x, y = key
@@ -52,26 +50,30 @@ def __setitem__(self, key, value):
5250
x, y = key
5351
self.pixel(x, y, value)
5452

55-
class Matrix8x8(HT16K33):
56-
"""A single matrix."""
53+
class Matrix16x8(Matrix8x8):
54+
"""The matrix wing."""
5755
def pixel(self, x, y, color=None):
5856
"""Get or set the color of a given pixel."""
59-
if not 0 <= x <= 7:
57+
if not 0 <= x <= 15:
6058
return None
6159
if not 0 <= y <= 7:
6260
return None
63-
x = (x - 1) % 8
64-
return super()._pixel(x, y, color)
65-
66-
def __getitem__(self, key):
67-
x, y = key
68-
return self.pixel(x, y)
61+
if x >= 8:
62+
x -= 8
63+
y += 8
64+
return super()._pixel(y, x, color)
6965

70-
def __setitem__(self, key, value):
71-
x, y = key
72-
self.pixel(x, y, value)
66+
class MatrixBackpack16x8(Matrix8x8):
67+
"""A double matrix backpack."""
68+
def pixel(self, x, y, color=None):
69+
"""Get or set the color of a given pixel."""
70+
if not 0 <= x <= 15:
71+
return None
72+
if not 0 <= y <= 7:
73+
return None
74+
return super()._pixel(x, y, color)
7375

74-
class Matrix8x8x2(HT16K33):
76+
class Matrix8x8x2(Matrix8x8):
7577
"""A bi-color matrix."""
7678
def pixel(self, x, y, color=None):
7779
"""Get or set the color of a given pixel."""
@@ -86,14 +88,6 @@ def pixel(self, x, y, color=None):
8688
return super()._pixel(y, x) | super()._pixel(y + 8, x) << 1
8789
return None
8890

89-
def __getitem__(self, key):
90-
x, y = key
91-
return self.pixel(x, y)
92-
93-
def __setitem__(self, key, value):
94-
x, y = key
95-
self.pixel(x, y, value)
96-
9791
def fill(self, color):
9892
"""Fill the whole display with the given color."""
9993
fill1 = 0xff if color & 0x01 else 0x00

examples/ht16k33_matrix_simpletest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# Create the matrix class.
1818
# This creates a 16x8 matrix:
1919
matrix = matrix.Matrix16x8(i2c)
20+
# Or this creates a 16x8 matrix backpack:
21+
# matrix = matrix.MatrixBackpack16x8(i2c)
2022
# Or this creates a 8x8 matrix:
2123
#matrix = matrix.Matrix8x8(i2c)
2224
# Or this creates a 8x8 bicolor matrix:

0 commit comments

Comments
 (0)