Skip to content

Commit

Permalink
Merge pull request #49 from makermelissa/matrix_scroll
Browse files Browse the repository at this point in the history
Refactored Matrix classes. Added additional class for backpack
  • Loading branch information
makermelissa authored Jan 15, 2020
2 parents 3557734 + 7031387 commit 4e2266c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
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

0 comments on commit 4e2266c

Please sign in to comment.