diff --git a/adafruit_ht16k33/matrix.py b/adafruit_ht16k33/matrix.py old mode 100644 new mode 100755 index 2687a52..a9fa7ac --- a/adafruit_ht16k33/matrix.py +++ b/adafruit_ht16k33/matrix.py @@ -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 @@ -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.""" @@ -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 diff --git a/examples/ht16k33_matrix_simpletest.py b/examples/ht16k33_matrix_simpletest.py index e420ecf..8656c07 100644 --- a/examples/ht16k33_matrix_simpletest.py +++ b/examples/ht16k33_matrix_simpletest.py @@ -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: