class SevenSegment: disp = None # Hexadecimal character lookup table (row 1 = 0..9, row 2 = A..F) digits = [ 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, \ 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71 ] # Constructor def __init__(self, address=0x70, debug=False): if (debug): print "Initializing a new instance of LEDBackpack at 0x%02X" % address self.disp = LEDBackpack(address=address, debug=debug) def writeDigitRaw(self, charNumber, value): "Sets a digit using the raw 16-bit value" if (charNumber > 7): return # Set the appropriate digit self.disp.setBufferRow(charNumber, value) def writeDigit(self, charNumber, value, dot=False): "Sets a single decimal or hexademical value (0..9 and A..F)" if (charNumber > 7): return if (value > 0xF): return # Set the appropriate digit self.disp.setBufferRow(charNumber, self.digits[value] | (dot << 7)) def setColon(self, state=True): "Enables or disables the colon character" # Warning: This function assumes that the colon is character '2', # which is the case on 4 char displays, but may need to be modified # if another display type is used if (state): self.disp.setBufferRow(2, 0xFFFF) else: self.disp.setBufferRow(2, 0) # Enabling/disabling small dots def writeDot(self, charNumber, dot): if charNumber > 4: return current = self.disp.getBufferRow(charNumber) #if dot: self.disp.setBufferRow(charNumber, current | (dot << 7))
class Bargraph: disp = None LED_OFF = 0 LED_RED = 1 LED_GREEN = 2 LED_YELLOW = 3 # Constructor def __init__(self, address=0x70, debug=False): self.debug = debug if self.debug: print "Initializing a new instance of LEDBackpack at 0x%02X" % address self.disp = LEDBackpack(address=address, debug=debug) def setLed(self, bar, color): if bar > 24: return if color > 3: return if bar < 12: c = bar / 4 else: c = (bar - 12) / 4 a = bar % 4; if bar >= 12: a += 4; if self.debug: print "Ano = %d Cath %d" % (a, c) bufRow = self.disp.getBufferRow(c) & ~((1 << a) | (1 << (a+8))) # turn off the LED if color == self.LED_RED: self.disp.setBufferRow(c, bufRow | (1 << a)) elif color == self.LED_YELLOW: self.disp.setBufferRow(c, bufRow | (1 << a) | (1 << (a+8))) elif color == self.LED_GREEN: self.disp.setBufferRow(c, bufRow | 1 << (a+8))