Skip to content

Refactored Matrix classes. Added additional class for backpack #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 22 additions & 28 deletions adafruit_ht16k33/matrix.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git"

class Matrix16x8(HT16K33):
"""A double matrix or the matrix wing."""
class Matrix8x8(HT16K33):
"""A single matrix."""
def pixel(self, x, y, color=None):
"""Get or set the color of a given pixel."""
if not 0 <= x <= 15:
if not 0 <= x <= 7:
return None
if not 0 <= y <= 7:
return None
if x >= 8:
x -= 8
y += 8
return super()._pixel(y, x, color)
x = (x - 1) % 8
return super()._pixel(x, y, color)

def __getitem__(self, key):
x, y = key
Expand All @@ -52,26 +50,30 @@ def __setitem__(self, key, value):
x, y = key
self.pixel(x, y, value)

class Matrix8x8(HT16K33):
"""A single matrix."""
class Matrix16x8(Matrix8x8):
"""The matrix wing."""
def pixel(self, x, y, color=None):
"""Get or set the color of a given pixel."""
if not 0 <= x <= 7:
if not 0 <= x <= 15:
return None
if not 0 <= y <= 7:
return None
x = (x - 1) % 8
return super()._pixel(x, y, color)

def __getitem__(self, key):
x, y = key
return self.pixel(x, y)
if x >= 8:
x -= 8
y += 8
return super()._pixel(y, x, color)

def __setitem__(self, key, value):
x, y = key
self.pixel(x, y, value)
class MatrixBackpack16x8(Matrix8x8):
"""A double matrix backpack."""
def pixel(self, x, y, color=None):
"""Get or set the color of a given pixel."""
if not 0 <= x <= 15:
return None
if not 0 <= y <= 7:
return None
return super()._pixel(x, y, color)

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

def __getitem__(self, key):
x, y = key
return self.pixel(x, y)

def __setitem__(self, key, value):
x, y = key
self.pixel(x, y, value)

def fill(self, color):
"""Fill the whole display with the given color."""
fill1 = 0xff if color & 0x01 else 0x00
Expand Down
2 changes: 2 additions & 0 deletions examples/ht16k33_matrix_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# Create the matrix class.
# This creates a 16x8 matrix:
matrix = matrix.Matrix16x8(i2c)
# Or this creates a 16x8 matrix backpack:
# matrix = matrix.MatrixBackpack16x8(i2c)
# Or this creates a 8x8 matrix:
#matrix = matrix.Matrix8x8(i2c)
# Or this creates a 8x8 bicolor matrix:
Expand Down