Skip to content

Commit 6aacd0b

Browse files
committed
segments: Add missing API for "dot" control on big 7-segments
There are 4 side LEDs around the 4 7-segments on 1.2" packages of HT16k33 (https://www.adafruit.com/product/1270). This commit adds an API to control them (set and get). There already was setter and getter to control "ampm" dot (the one at the top-right). This API is still working but now use the new added functions.
1 parent 1f60840 commit 6aacd0b

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

adafruit_ht16k33/segments.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,20 +308,39 @@ def __init__(self, i2c, address=0x70, auto_write=True):
308308
super().__init__(i2c, address, auto_write)
309309
self.colon = Colon(self, 2)
310310

311+
def setindicator(self, index, value):
312+
""" Set side LEDs (dots)
313+
Index is as follow :
314+
* 0 : two dots at the center
315+
* 1 : top-left dot
316+
* 2 : bottom-left dot
317+
* 3 : right dot (also ampm indicator)
318+
"""
319+
bitmask = 1 << (index + 1)
320+
current = self._get_buffer(0x04)
321+
if value:
322+
self._set_buffer(0x04, current | bitmask)
323+
else:
324+
self._set_buffer(0x04, current & ~bitmask)
325+
if self._auto_write:
326+
self.show()
327+
328+
def getindicator(self, index):
329+
""" Get side LEDs (dots)
330+
See setindicator() for indexes
331+
"""
332+
bitmask = 1 << (index + 1)
333+
return self._get_buffer(0x04) & bitmask
334+
311335
@property
312336
def ampm(self):
313337
"""The AM/PM indicator."""
314-
return bool(self._get_buffer(0x04) & 0x10)
338+
return bool(self.getindicator(3))
315339

316340
@ampm.setter
317341
def ampm(self, value):
318-
current = self._get_buffer(0x04)
319-
if value:
320-
self._set_buffer(0x04, current | 0x10)
321-
else:
322-
self._set_buffer(0x04, current & ~0x10)
323-
if self._auto_write:
324-
self.show()
342+
self.setindicator(3, value)
343+
325344

326345
class Colon():
327346
"""Helper class for controlling the colons. Not intended for direct use."""

0 commit comments

Comments
 (0)