Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Commit 4fa7c00

Browse files
committed
Added raw functions for colon (model-specific)
1 parent a8ea1eb commit 4fa7c00

File tree

1 file changed

+63
-36
lines changed

1 file changed

+63
-36
lines changed

Adafruit_LEDBackpack/Adafruit_7Segment.py

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,72 @@
88
# 7-Segment Display
99
# ===========================================================================
1010

11+
# The colon row
12+
COLON_ROW = 2
13+
1114
# This class is meant to be used with the four-character, seven segment
1215
# displays available from Adafruit
1316

1417
class SevenSegment:
15-
disp = None
18+
19+
# Enum creator
20+
def enum(**enums):
21+
return type('Enum', (), enums)
22+
23+
disp = None
1624

17-
# Hexadecimal character lookup table (row 1 = 0..9, row 2 = A..F)
18-
digits = [ 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, \
19-
0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71 ]
20-
21-
# Constructor
22-
def __init__(self, address=0x70, debug=False):
23-
if (debug):
24-
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
25-
self.disp = LEDBackpack(address=address, debug=debug)
26-
27-
def writeDigitRaw(self, charNumber, value):
28-
"Sets a digit using the raw 16-bit value"
29-
if (charNumber > 7):
30-
return
31-
# Set the appropriate digit
32-
self.disp.setBufferRow(charNumber, value)
33-
34-
def writeDigit(self, charNumber, value, dot=False):
35-
"Sets a single decimal or hexademical value (0..9 and A..F)"
36-
if (charNumber > 7):
37-
return
38-
if (value > 0xF):
39-
return
40-
# Set the appropriate digit
41-
self.disp.setBufferRow(charNumber, self.digits[value] | (dot << 7))
42-
43-
def setColon(self, state=True):
44-
"Enables or disables the colon character"
45-
# Warning: This function assumes that the colon is character '2',
46-
# which is the case on 4 char displays, but may need to be modified
47-
# if another display type is used
48-
if (state):
49-
self.disp.setBufferRow(2, 0xFFFF)
50-
else:
51-
self.disp.setBufferRow(2, 0)
25+
# Hexadecimal character lookup table (row 1 = 0..9, row 2 = A..F)
26+
digits = [ 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, \
27+
0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71 ]
28+
29+
# The parts of the colon
30+
ColonParts = enum(POINT = 0b00010000,
31+
LEFT_COLON_FULL = 0b00001100,
32+
LEFT_COLON_BOTTOM_POINT = 0b00001000,
33+
LEFT_COLON_TOP_POINT = 0b00000100,
34+
RIGHT_COLON = 0b00000010)
35+
36+
# Constructor
37+
def __init__(self, address=0x70, debug=False):
38+
if (debug):
39+
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
40+
self.disp = LEDBackpack(address=address, debug=debug)
41+
42+
def writeDigitRaw(self, charNumber, value):
43+
"Sets a digit using the raw 16-bit value"
44+
if (charNumber > 7):
45+
return
46+
# Set the appropriate digit
47+
self.disp.setBufferRow(charNumber, value)
48+
49+
def writeDigit(self, charNumber, value, dot=False):
50+
"Sets a single decimal or hexademical value (0..9 and A..F)"
51+
if (charNumber > 7):
52+
return
53+
if (value > 0xF):
54+
return
55+
# Set the appropriate digit
56+
self.disp.setBufferRow(charNumber, self.digits[value] | (dot << 7))
57+
58+
def setColonRaw(self, state=True):
59+
"Enables or disables the colon character"
60+
# General for 7segments
61+
# Warning: This function assumes that the colon is character '2',
62+
# which is the case on 4 char displays, but may need to be modified
63+
# if another display type is used
64+
if (state):
65+
self.disp.setBufferRow(COLON_ROW, 0xFFFF)
66+
else:
67+
self.disp.setBufferRow(COLON_ROW, 0)
5268

69+
def setColon(self, colonPart=ColonParts.RIGHT_COLON, state=True):
70+
"Enables or disables a specific colon character"
71+
# Specific for 7Segment model Luckylight L1311094A
72+
# KW4-12041CLA
73+
# and backpack model Adafruit HT16K33
74+
# (Not tested on any other model)
75+
# colonPart should be called as SevenSegment.ColonParts.PART_NAME
76+
if (state):
77+
self.disp.setBufferRow(COLON_ROW, self.disp.getBufferRow(COLON_ROW) | colonPart)
78+
else:
79+
self.disp.setBufferRow(COLON_ROW, self.disp.getBufferRow(COLON_ROW) & ~colonPart)

0 commit comments

Comments
 (0)