-
Notifications
You must be signed in to change notification settings - Fork 28
added auto_write #14
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
added auto_write #14
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,10 +40,12 @@ | |
|
||
class HT16K33: | ||
"""The base class for all displays. Contains common methods.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is a base class for multiple things, I'm not sure it's applicable to expand this docstring to the same extent as, for example, the DotStar lib: https://github.com/adafruit/Adafruit_CircuitPython_DotStar/blob/af25424ee7dbebea3e5d77390c017018ffa52d36/adafruit_dotstar.py#L51 If it is applicable, we should consider doing it. If it's not, please disregard. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went ahead and put in the |
||
def __init__(self, i2c, address=0x70): | ||
def __init__(self, i2c, address=0x70, auto_write=True): | ||
self.i2c_device = i2c_device.I2CDevice(i2c, address) | ||
self._temp = bytearray(1) | ||
self._buffer = bytearray(17) | ||
self._auto_write = None | ||
self._auto_write = auto_write | ||
self.fill(0) | ||
self._write_cmd(_HT16K33_OSCILATOR_ON) | ||
self._blink_rate = None | ||
|
@@ -85,6 +87,18 @@ def brightness(self, brightness): | |
self._write_cmd(_HT16K33_CMD_BRIGHTNESS | brightness) | ||
return None | ||
|
||
@property | ||
def auto_write(self): | ||
"""Auto write updates to the display.""" | ||
return self._auto_write | ||
|
||
@auto_write.setter | ||
def auto_write(self, auto_write): | ||
if isinstance(auto_write, bool): | ||
self._auto_write = auto_write | ||
else: | ||
raise ValueError('Must set to either True or False.') | ||
|
||
def show(self): | ||
"""Refresh the display and show the changes.""" | ||
with self.i2c_device: | ||
|
@@ -97,6 +111,8 @@ def fill(self, color): | |
fill = 0xff if color else 0x00 | ||
for i in range(16): | ||
self._buffer[i+1] = fill | ||
if self._auto_write: | ||
self.show() | ||
|
||
def _pixel(self, x, y, color=None): | ||
mask = 1 << x | ||
|
@@ -108,6 +124,8 @@ def _pixel(self, x, y, color=None): | |
else: | ||
self._buffer[(y * 2) + 1] &= ~(mask & 0xff) | ||
self._buffer[(y * 2) + 2] &= ~(mask >> 8) | ||
if self._auto_write: | ||
self.show() | ||
return None | ||
|
||
def _set_buffer(self, i, value): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,15 +24,12 @@ | |
# Finally you can optionally specify a custom I2C address of the HT16k33 like: | ||
#matrix = matrix.Matrix16x8(i2c, address=0x70) | ||
|
||
# Clear the matrix. Always call show after changing pixels to make the display | ||
# update visible! | ||
# Clear the matrix. | ||
matrix.fill(0) | ||
matrix.show() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe leave this in, but commented out, denoting that it is required if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if I agree with this. I can see where @sommersoft is coming from, but I think it can start bloating the simple examples to include all the potentially necessary code if you changed the default kwargs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had something in there, but then took it out for same reason @kattni mentions. I think this is what I had, how about this: matrix.fill(0)
# If you turn auto_write off, you will need to call show() to update the display
# matrix.show() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can agree with the bloat concern. Having the parameters in the API documentation is enough for me. |
||
|
||
# Set a pixel in the origin 0,0 position. | ||
matrix.pixel(0, 0, 1) | ||
matrix[0, 0] = 1 | ||
# Set a pixel in the middle 8, 4 position. | ||
matrix.pixel(8, 4, 1) | ||
matrix[8, 4] = 1 | ||
# Set a pixel in the opposite 15, 7 position. | ||
matrix.pixel(15, 7, 1) | ||
matrix.show() | ||
matrix[15, 7] = 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
# Author: Tony DiCola | ||
# License: Public Domain | ||
|
||
import time | ||
|
||
# Import all board pins. | ||
from board import * | ||
import busio | ||
|
@@ -22,11 +24,14 @@ | |
# Finally you can optionally specify a custom I2C address of the HT16k33 like: | ||
#display = segments.Seg7x4(i2c, address=0x70) | ||
|
||
# Clear the display. Always call show after changing the display to make the | ||
# update visible! | ||
# Clear the display. | ||
display.fill(0) | ||
display.show() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
|
||
# Can just print a number | ||
display.print(42) | ||
time.sleep(2) | ||
|
||
# Or, can set indivdual digits / characters | ||
# Set the first character to '1': | ||
display[0] = '1' | ||
# Set the second character to '2': | ||
|
@@ -35,5 +40,3 @@ | |
display[2] = 'A' | ||
# Set the forth character to 'B': | ||
display[3] = 'B' | ||
# Make sure to call show to see the changes above on the display! | ||
display.show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a note here that
auto_write
is on by default?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that just to make it more obvious than what Read The Docs will have? Otherwise, it's similar to the default value for
address
.