Skip to content

Commit 5f5ea25

Browse files
authored
Merge pull request mcauser#3 from larsks/feature/dots
allow dots in strings
2 parents e7210c4 + 7c04995 commit 5f5ea25

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tm1637.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,29 @@ def scroll(self, string, delay=250):
173173
for i in range(len(segments) + 5):
174174
self.write(data[0+i:4+i])
175175
sleep_ms(delay)
176+
177+
178+
class TM1637Decimal(TM1637):
179+
"""Library for quad 7-segment LED modules based on the TM1637 LED driver.
180+
181+
This class is meant to be used with decimal display modules (modules
182+
that have a decimal point after each 7-segment LED).
183+
"""
184+
185+
def encode_string(self, string):
186+
"""Convert a string to LED segments.
187+
188+
Convert an up to 4 character length string containing 0-9, a-f,
189+
space, dash and '.' to an array of segments, matching the length of
190+
the source string.
191+
"""
192+
193+
segments = bytearray(len(string))
194+
j = 0
195+
for i in range(len(string)):
196+
if string[i] == '.' and j > 0:
197+
segments[j-1] |= 0b10000000
198+
continue
199+
segments[j] = self.encode_char(string[i])
200+
j += 1
201+
return segments

0 commit comments

Comments
 (0)