-
Notifications
You must be signed in to change notification settings - Fork 0
/
Adafruit_7SegmentPlus.py
72 lines (61 loc) · 2.32 KB
/
Adafruit_7SegmentPlus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python
import time
import datetime
from Adafruit_LEDBackpack import LEDBackpack
# ===========================================================================
# 7-Segment Display
# ===========================================================================
# This class is meant to be used with the four-character, seven segment
# displays available from Adafruit
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)
def setSpecialH(self, charNumber, state=True):
"Displays an H on the display. I use this for Humidity"
self.disp.setBufferRow(charNumber, 0x76)
#
#class FullDisplaySevenSegment:
# def __init__(self, address=0x70, debug=False):
# if (debug):
# print "Initializing a new instance of LEDBackpack at 0x%02X" % address
# self.segment = SevenSegment(address=address)
# self.segment.disp.setBrightness(10)
# self.segment.disp.clear()
#
# def displayMessage(messageString):
# self.segment.writeDigit(0,str(messageString))
# self.segment.writeDigit(0)
# self.segment.writeDigit(0)
# self.segment.writeDigit(0)
#
#