Skip to content

Commit c090f6b

Browse files
committed
Merge pull request adafruit#79 from boxysean/master
Bi-Color bargraph interface
2 parents b11ed08 + c07439a commit c090f6b

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/python
2+
3+
import time
4+
import datetime
5+
from Adafruit_LEDBackpack import LEDBackpack
6+
7+
# ===========================================================================
8+
# Bargraph Display
9+
# ===========================================================================
10+
11+
# This class is meant to be used with the 24-LED bicolor bargraph
12+
# displays available from Adafruit
13+
14+
class Bargraph:
15+
disp = None
16+
17+
LED_OFF = 0
18+
LED_RED = 1
19+
LED_GREEN = 2
20+
LED_YELLOW = 3
21+
22+
# Constructor
23+
def __init__(self, address=0x70, debug=False):
24+
self.debug = debug
25+
26+
if self.debug:
27+
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
28+
self.disp = LEDBackpack(address=address, debug=debug)
29+
30+
def setLed(self, bar, color):
31+
if bar > 24:
32+
return
33+
if color > 3:
34+
return
35+
36+
if bar < 12:
37+
c = bar / 4
38+
else:
39+
c = (bar - 12) / 4
40+
41+
a = bar % 4;
42+
if bar >= 12:
43+
a += 4;
44+
45+
if self.debug:
46+
print "Ano = %d Cath %d" % (a, c)
47+
48+
bufRow = self.disp.getBufferRow(c) & ~((1 << a) | (1 << (a+8))) # turn off the LED
49+
50+
if color == self.LED_RED:
51+
self.disp.setBufferRow(c, bufRow | (1 << a))
52+
elif color == self.LED_YELLOW:
53+
self.disp.setBufferRow(c, bufRow | (1 << a) | (1 << (a+8)))
54+
elif color == self.LED_GREEN:
55+
self.disp.setBufferRow(c, bufRow | 1 << (a+8))

Adafruit_LEDBackpack/Adafruit_LEDBackpack.py

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ def setBufferRow(self, row, value, update=True):
6464
if (update):
6565
self.writeDisplay() # Update the display
6666

67+
def getBufferRow(self, row):
68+
"Returns a single 16-bit entry in the 8*16-bit buffer"
69+
if (row > 7):
70+
return
71+
return self.__buffer[row]
72+
6773
def getBuffer(self):
6874
"Returns a copy of the raw buffer contents"
6975
bufferCopy = copy(self.__buffer)

Adafruit_LEDBackpack/ex_bargraph.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/python
2+
3+
import time
4+
import datetime
5+
from Adafruit_Bargraph import Bargraph
6+
7+
# ===========================================================================
8+
# Scroll through colors example
9+
# ===========================================================================
10+
bargraph = Bargraph(address=0x70)
11+
12+
print "Press CTRL+C to exit"
13+
14+
while(True):
15+
for color in range(1, 4):
16+
for i in range(24):
17+
print i
18+
bargraph.setLed(i, color)
19+
time.sleep(0.05)

0 commit comments

Comments
 (0)