Skip to content

Add support for 1.2" 4-Digit 7-Segment Displays #18

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 10 commits into from
Jul 13, 2018
Merged
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
49 changes: 48 additions & 1 deletion adafruit_ht16k33/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@
0x40, # -
)


class Seg14x4(HT16K33):
"""Alpha-numeric, 14-segment display."""
def print(self, value):
Expand Down Expand Up @@ -256,3 +255,51 @@ def _put(self, char, index=0):
else:
return
self._set_buffer(index, NUMBERS[character])

class BigSeg7x4(Seg7x4):
"""Numeric 7-segment display. It has the same methods as the alphanumeric display, but only
supports displaying a limited set of characters."""
def __init__(self, i2c, address=0x70, auto_write=True):
super().__init__(i2c, address, auto_write)
self.colon = Colon(self, 2)

@property
def ampm(self):
"""The AM/PM indicator."""
return bool(self._get_buffer(0x04) & 0x10)

@ampm.setter
def ampm(self, value):
current = self._get_buffer(0x04)
if value:
self._set_buffer(0x04, current | 0x10)
else:
self._set_buffer(0x04, current & ~0x10)
if self._auto_write:
self.show()

class Colon():
"""Helper class for controlling the colons. Not intended for direct use."""
#pylint: disable=protected-access

MASKS = (0x02, 0x0C)

def __init__(self, disp, num_of_colons=1):
self._disp = disp
self._num_of_colons = num_of_colons

def __setitem__(self, key, value):
if key > self._num_of_colons - 1:
raise ValueError("Trying to set a non-existent colon.")
current = self._disp._get_buffer(0x04)
if value:
self._disp._set_buffer(0x04, current | self.MASKS[key])
else:
self._disp._set_buffer(0x04, current & ~self.MASKS[key])
if self._disp.auto_write:
self._disp.show()

def __getitem__(self, key):
if key > self._num_of_colons - 1:
raise ValueError("Trying to access a non-existent colon.")
return bool(self._disp._get_buffer(0x04) & self.MASKS[key])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest adding the # pylint: enable=your-lint-complaint wherever it needs to be in the event that something is eventually added to the end of this file. I'm not certain where it needs to go - it may need to encompass the entire class, or it may be able to go on line 205. Please experiment to find the best location for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to inside the class. The disables apparently work at a code block level, so I think this should limit to with the class itself.