Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Commit 9f638e2

Browse files
committed
updated LEDBackpack with my scrolling text modifications
1 parent 868dcbc commit 9f638e2

File tree

6 files changed

+880
-24
lines changed

6 files changed

+880
-24
lines changed

Adafruit_LEDBackpack/Adafruit_8x8.py

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,80 @@
11
#!/usr/bin/python
2+
# Updated to allow for scrolling text with the Adafruit_GFX.py library
3+
# ColorEightByEight not updated yet.
24

3-
import time
4-
import datetime
55
from Adafruit_LEDBackpack import LEDBackpack
66

77
# ===========================================================================
88
# 8x8 Pixel Display
99
# ===========================================================================
1010

11-
class EightByEight:
12-
disp = None
11+
class EightByEight(LEDBackpack):
12+
#disp = None
13+
rotation = None
1314

1415
# Constructor
1516
def __init__(self, address=0x70, debug=False):
1617
if (debug):
1718
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
18-
self.disp = LEDBackpack(address=address, debug=debug)
19+
LEDBackpack.__init__(self, 8, 8, address, debug)
20+
self.rotation = 0
1921

2022
def writeRowRaw(self, charNumber, value):
21-
"Sets a row of pixels using a raw 16-bit value"
23+
#"Sets a row of pixels using a raw 16-bit value"
2224
if (charNumber > 7):
2325
return
2426
# Set the appropriate row
25-
self.disp.setBufferRow(charNumber, value)
27+
self.setBufferRow(charNumber, value)
2628

2729
def clearPixel(self, x, y):
28-
"A wrapper function to clear pixels (purely cosmetic)"
30+
#"A wrapper function to clear pixels (purely cosmetic)"
2931
self.setPixel(x, y, 0)
3032

31-
def setPixel(self, x, y, color=1):
32-
"Sets a single pixel"
33-
if (x >= 8):
33+
def drawPixel(self, x, y, color=1):
34+
#"Sets a single pixel"
35+
if ((y < 0) or (y >= 8)):
3436
return
35-
if (y >= 8):
37+
if ((x < 0) or (x >= 8)):
3638
return
39+
40+
# Added rotation code 4/16/13 - RH
41+
if self.rotation == 1:
42+
x, y = self.swap(x, y)
43+
x = 8 - x - 1
44+
elif self.rotation == 2:
45+
x = 8 - x - 1
46+
y = 8 - y - 1
47+
elif self.rotation == 3:
48+
x, y = self.swap(x, y)
49+
y = 8 - y - 1
50+
3751
x += 7 # ATTN: This might be a bug? On the color matrix, this causes x=0 to draw on the last line instead of the first.
3852
x %= 8
3953
# Set the appropriate pixel
40-
buffer = self.disp.getBuffer()
54+
buffer = self.getBuffer()
4155
if (color):
42-
self.disp.setBufferRow(y, buffer[y] | 1 << x)
43-
else:
44-
self.disp.setBufferRow(y, buffer[y] & ~(1 << x))
56+
self.setBufferRow(y, buffer[y] | 1 << x, False) # disable update option to determine if writeDisplay() is called when
57+
else: # writing a bunch of pixels. Speeds things up dramatically when scrolling
58+
self.setBufferRow(y, buffer[y] & ~(1 << x), False) # text on multiple matrices. Call writeDisplay() after updating buffer.
59+
60+
# Used to rotate display 4/16/13 - RH
61+
# Corrected for dual output 6/5/13 - RH
62+
def swap(self, x, y):
63+
temp = x
64+
x = y
65+
y = temp
66+
return (x, y)
4567

46-
def clear(self):
47-
"Clears the entire display"
48-
self.disp.clear()
68+
# Added 6/3/13 - RH
69+
def printMessage(self, text):
70+
for letter in range(0, len(text)):
71+
self.write(text[letter])
72+
if (self.debug):
73+
print(text[letter])
4974

5075
class ColorEightByEight(EightByEight):
5176
def setPixel(self, x, y, color=1):
52-
"Sets a single pixel"
77+
#"Sets a single pixel"
5378
if (x >= 8):
5479
return
5580
if (y >= 8):

0 commit comments

Comments
 (0)