# -*- coding: utf-8-*- # # This file is part of stdd, the simple time display daemon, # written by Helmut Pozimski , # licensed under the 3-clause BSD license # This file was originally written by Written by Limor Fried, Kevin Townsend # and Mikey Sklar for Adafruit Industries. BSD license, # all text above must be included in any redistribution """ =========================================================================== 7-Segment Display =========================================================================== This class is meant to be used with the four-character, seven segment displays available from Adafruit. """ from __future__ import print_function from adafruit_7segment.ledbackpack import LEDBackpack class SevenSegment(object): """This class represents the seven segment display and allows to access and write data to it. """ 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 write_digit_raw(self, char_number, value): """Sets a digit using the raw 16-bit value""" if char_number > 7: return # Set the appropriate digit self.disp.set_buffer_row(char_number, value) def write_digit(self, char_number, value, dot=False): """Sets a single decimal or hexademical value (0..9 and A..F)""" if char_number > 7: return if value > 0xF: return # Set the appropriate digit self.disp.set_buffer_row(char_number, self.digits[value] | (dot << 7)) def set_colon(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.set_buffer_row(2, 0xFFFF) else: self.disp.set_buffer_row(2, 0) def set_brightness(self, brightness): """ Sets the brightness. """ self.disp.set_brightness(brightness)