Skip to content

Commit 5b3f89f

Browse files
author
mprice
committed
Added ColorEightByEight class and example program for Adafruit Bicolor LED Square Pixel Matrix with I2C Backpack
Added note about possible pixel indexing bug in the non-color version. I don't have the non-color version to test with. Added note about possible unintentional color "blending" bug in the Arduino color version.
1 parent 8b7178b commit 5b3f89f

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

Adafruit_LEDBackpack/Adafruit_8x8.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def setPixel(self, x, y, color=1):
3333
if (x >= 8):
3434
return
3535
if (y >= 8):
36-
return
37-
x += 7
36+
return
37+
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.
3838
x %= 8
3939
# Set the appropriate pixel
4040
buffer = self.disp.getBuffer()
@@ -47,3 +47,29 @@ def clear(self):
4747
"Clears the entire display"
4848
self.disp.clear()
4949

50+
class ColorEightByEight(EightByEight):
51+
def setPixel(self, x, y, color=1):
52+
"Sets a single pixel"
53+
if (x >= 8):
54+
return
55+
if (y >= 8):
56+
return
57+
58+
x %= 8
59+
60+
# Set the appropriate pixel
61+
buffer = self.disp.getBuffer()
62+
63+
# TODO : Named color constants?
64+
# ATNN : This code was mostly taken from the arduino code, but with the addition of clearing the other bit when setting red or green.
65+
# The arduino code does not do that, and might have the bug where if you draw red or green, then the other color, it actually draws yellow.
66+
# The bug doesn't show up in the examples because it's always clearing.
67+
68+
if (color == 1):
69+
self.disp.setBufferRow(y, (buffer[y] | (1 << x)) & ~(1 << (x+8)) )
70+
elif (color == 2):
71+
self.disp.setBufferRow(y, (buffer[y] | 1 << (x+8)) & ~(1 << x) )
72+
elif (color == 3):
73+
self.disp.setBufferRow(y, buffer[y] | (1 << (x+8)) | (1 << x) )
74+
else:
75+
self.disp.setBufferRow(y, buffer[y] & ~(1 << x) & ~(1 << (x+8)) )

Adafruit_LEDBackpack/ex_8x8_color_pixels.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,7 @@
1717
while(True):
1818
iter += 1
1919

20-
print (iter % 4)
21-
2220
for x in range(0, 8):
2321
for y in range(0, 8):
24-
grid.setPixel(x, y, iter%4 )
22+
grid.setPixel(x, y, iter % 4 )
2523
time.sleep(0.02)
26-
27-
# I think there is another bug here that drawing red or green after yellow doesn't clear the other component until you draw a blank
28-
29-
# time.sleep(0.5)
30-
# grid.clear()
31-
# time.sleep(0.5)

0 commit comments

Comments
 (0)