Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Adafruit_LEDBackpack/Adafruit_Bargraph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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))
6 changes: 6 additions & 0 deletions Adafruit_LEDBackpack/Adafruit_LEDBackpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def setBufferRow(self, row, value, update=True):
if (update):
self.writeDisplay() # Update the display

def getBufferRow(self, row):
"Returns a single 16-bit entry in the 8*16-bit buffer"
if (row > 7):
return
return self.__buffer[row]

def getBuffer(self):
"Returns a copy of the raw buffer contents"
bufferCopy = copy(self.__buffer)
Expand Down
19 changes: 19 additions & 0 deletions Adafruit_LEDBackpack/ex_bargraph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/python

import time
import datetime
from Adafruit_Bargraph import Bargraph

# ===========================================================================
# Scroll through colors example
# ===========================================================================
bargraph = Bargraph(address=0x70)

print "Press CTRL+C to exit"

while(True):
for color in range(1, 4):
for i in range(24):
print i
bargraph.setLed(i, color)
time.sleep(0.05)