Skip to content

Commit 07119c6

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 3e64ef3 commit 07119c6

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
@@ -275,20 +275,39 @@ def __init__(self, i2c, address=0x70, auto_write=True):
275275
super().__init__(i2c, address, auto_write)
276276
self.colon = Colon(self, 2)
277277

278+
def setindicator(self, index, value):
279+
""" Set side LEDs (dots)
280+
Index is as follow :
281+
* 0 : two dots at the center
282+
* 1 : top-left dot
283+
* 2 : bottom-left dot
284+
* 3 : right dot (also ampm indicator)
285+
"""
286+
bitmask = 1 << (index + 1)
287+
current = self._get_buffer(0x04)
288+
if value:
289+
self._set_buffer(0x04, current | bitmask)
290+
else:
291+
self._set_buffer(0x04, current & ~bitmask)
292+
if self._auto_write:
293+
self.show()
294+
295+
def getindicator(self, index):
296+
""" Get side LEDs (dots)
297+
See setindicator() for indexes
298+
"""
299+
bitmask = 1 << (index + 1)
300+
return self._get_buffer(0x04) & bitmask
301+
278302
@property
279303
def ampm(self):
280304
"""The AM/PM indicator."""
281-
return bool(self._get_buffer(0x04) & 0x10)
305+
return bool(self.getindicator(3))
282306

283307
@ampm.setter
284308
def ampm(self, value):
285-
current = self._get_buffer(0x04)
286-
if value:
287-
self._set_buffer(0x04, current | 0x10)
288-
else:
289-
self._set_buffer(0x04, current & ~0x10)
290-
if self._auto_write:
291-
self.show()
309+
self.setindicator(3, value)
310+
292311

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

0 commit comments

Comments
 (0)