Skip to content

Commit 0b56d57

Browse files
committed
Create Adafruit_16x8.py
Created a python script for the Adafruit 16x8 LED backpack.
1 parent 2c9ffd7 commit 0b56d57

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Adafruit_LEDBackpack/Adafruit_16x8.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/python
2+
3+
import time
4+
import datetime
5+
from Adafruit_LEDBackpack import LEDBackpack
6+
7+
# ===========================================================================
8+
# 16x8 Pixel Display
9+
# ===========================================================================
10+
11+
class SixteenByEight:
12+
disp = None
13+
14+
# Constructor
15+
def __init__(self, address=0x70, debug=False):
16+
if (debug):
17+
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
18+
self.disp = LEDBackpack(address=address, debug=debug)
19+
20+
def writeRowRaw(self, charNumber, value):
21+
"Sets a row of pixels using a raw 16-bit value"
22+
if (charNumber > 7):
23+
return
24+
# Set the appropriate row
25+
self.disp.setBufferRow(charNumber, value)
26+
27+
def clearPixel(self, x, y):
28+
"A wrapper function to clear pixels (purely cosmetic)"
29+
self.setPixel(x, y, 0)
30+
31+
def setPixel(self, x, y, color=1):
32+
"Sets a single pixel"
33+
if (x >= 16):
34+
return
35+
if (y >= 8):
36+
return
37+
x += 16 # ATTN: This might be a bug? On the color matrix, this causes x=0 to draw on the last line instead of the first.
38+
x %= 16
39+
# Set the appropriate pixel
40+
buffer = self.disp.getBuffer()
41+
if (color):
42+
self.disp.setBufferRow(y, buffer[y] | 1 << x)
43+
else:
44+
self.disp.setBufferRow(y, buffer[y] & ~(1 << x))
45+
46+
def clear(self):
47+
"Clears the entire display"
48+
self.disp.clear()

0 commit comments

Comments
 (0)