1313
1414class SevenSegment :
1515 disp = None
16-
16+ invert = False
17+
1718 # Hexadecimal character lookup table (row 1 = 0..9, row 2 = A..F)
1819 digits = [ 0x3F , 0x06 , 0x5B , 0x4F , 0x66 , 0x6D , 0x7D , 0x07 , 0x7F , 0x6F , \
1920 0x77 , 0x7C , 0x39 , 0x5E , 0x79 , 0x71 ]
2021
22+ # The same, but upside-down
23+ idigits = [ 0x3F , 0x30 , 0x5B , 0x79 , 0x74 , 0x6D , 0x6F , 0x38 , 0x7F , 0x7D , \
24+ 0x7E , 0x67 , 0x0F , 0x73 , 0x4F , 0x4E ]
25+
2126 # Constructor
2227 def __init__ (self , address = 0x70 , debug = False ):
2328 if (debug ):
@@ -37,14 +42,23 @@ def writeDigit(self, charNumber, value, dot=False):
3742 return
3843 if (value > 0xF ):
3944 return
45+
46+ # Decide which digit set to use: check self.invert
47+ d = self .idigits [value ] if self .invert else self .digits [value ]
48+
49+ # If inverted, also reverse the character positions
50+ c = (4 - charNumber ) if self .invert else charNumber
51+
4052 # Set the appropriate digit
41- self .disp .setBufferRow (charNumber , self . digits [ value ] | (dot << 7 ))
53+ self .disp .setBufferRow (c , d | (dot << 7 ))
4254
4355 def setColon (self , state = True ):
4456 "Enables or disables the colon character"
4557 # Warning: This function assumes that the colon is character '2',
4658 # which is the case on 4 char displays, but may need to be modified
4759 # if another display type is used
60+ # This sets all non-digit LEDs. Change (2,0xFFFF) to (2,2) to just
61+ # set colon on the 1.2" 7-Segment display.
4862 if (state ):
4963 self .disp .setBufferRow (2 , 0xFFFF )
5064 else :
0 commit comments