Mercurial > micropython-ht16k33
changeset 15:4e29ef2ed337 default tip
Add support for bi-color matrix
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Wed, 17 Aug 2016 13:25:17 +0200 |
| parents | 8ec76a6b0661 |
| children | |
| files | ht16k33_matrix.py |
| diffstat | 1 files changed, 27 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/ht16k33_matrix.py Wed Jun 29 11:43:28 2016 +0200 +++ b/ht16k33_matrix.py Wed Aug 17 13:25:17 2016 +0200 @@ -32,7 +32,7 @@ _HT16K33_BLINK_DISPLAYON | rate << 1) def brightness(self, brightness): - """Get or set the brightness.""" + """Get or set the brightness (0-15).""" if brightness is None: return self._brightness brightness = brightness & 0x0F @@ -66,7 +66,7 @@ """The double matrix.""" def pixel(self, x, y, color=None): - """Set a single pixel in the frame buffer to specified color.""" + """Set a single pixel to specified color.""" if not 0 <= x <= 15: return if not 0 <= y <= 7: @@ -81,10 +81,34 @@ """The single matrix.""" def pixel(self, x, y, color=None): - """Set a single pixel in the frame buffer to specified color.""" + """Set a single pixel to specified color.""" if not 0 <= x <= 7: return if not 0 <= y <= 7: return x = (x - 1) % 8 return super()._pixel(x, y, color) + + +class Matrix8x8x2(HT16K33): + """The bi-color matrix.""" + + def pixel(self, x, y, color=None): + """Set a single pixel to specified color.""" + if not 0 <= x <= 7: + return + if not 0 <= y <= 7: + return + if color is not None: + super()._pixel(y, x, (color & 0x01)) + super()._pixel(y + 8, x, (color >> 1) & 0x01) + else: + return super()._pixel(y, x) | super()._pixel(y + 8, x) << 1 + + def fill(self, color): + """Fill the display with given color.""" + fill1 = 0xff if color & 0x01 else 0x00 + fill2 = 0xff if color & 0x02 else 0x00 + for i in range(8): + self.buffer[i * 2] = fill1 + self.buffer[i * 2 + 1] = fill2
