forked from adafruit/Adafruit-Raspberry-Pi-Python-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdafruit_Bargraph.py
55 lines (42 loc) · 1.31 KB
/
Adafruit_Bargraph.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
#!/usr/bin/python
import time
import datetime
from Adafruit_LEDBackpack import LEDBackpack
# ===========================================================================
# Bargraph Display
# ===========================================================================
# This class is meant to be used with the 24-LED bicolor bargraph
# displays available from Adafruit
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))