Permalink
Browse files

Added ColorEightByEight class and example program for Adafruit Bicolo…

…r 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.
  • Loading branch information...
1 parent 8b7178b commit 5b3f89f239c3c4a01fb01d2efbaae5c21b435fda mprice committed Sep 30, 2012
Showing with 29 additions and 11 deletions.
  1. +28 −2 Adafruit_LEDBackpack/Adafruit_8x8.py
  2. +1 −9 Adafruit_LEDBackpack/ex_8x8_color_pixels.py
@@ -33,8 +33,8 @@ def setPixel(self, x, y, color=1):
if (x >= 8):
return
if (y >= 8):
- return
- x += 7
+ return
+ 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.
x %= 8
# Set the appropriate pixel
buffer = self.disp.getBuffer()
@@ -47,3 +47,29 @@ def clear(self):
"Clears the entire display"
self.disp.clear()
+class ColorEightByEight(EightByEight):
+ def setPixel(self, x, y, color=1):
+ "Sets a single pixel"
+ if (x >= 8):
+ return
+ if (y >= 8):
+ return
+
+ x %= 8
+
+ # Set the appropriate pixel
+ buffer = self.disp.getBuffer()
+
+ # TODO : Named color constants?
+ # ATNN : This code was mostly taken from the arduino code, but with the addition of clearing the other bit when setting red or green.
+ # 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.
+ # The bug doesn't show up in the examples because it's always clearing.
+
+ if (color == 1):
+ self.disp.setBufferRow(y, (buffer[y] | (1 << x)) & ~(1 << (x+8)) )
+ elif (color == 2):
+ self.disp.setBufferRow(y, (buffer[y] | 1 << (x+8)) & ~(1 << x) )
+ elif (color == 3):
+ self.disp.setBufferRow(y, buffer[y] | (1 << (x+8)) | (1 << x) )
+ else:
+ self.disp.setBufferRow(y, buffer[y] & ~(1 << x) & ~(1 << (x+8)) )
@@ -17,15 +17,7 @@
while(True):
iter += 1
- print (iter % 4)
-
for x in range(0, 8):
for y in range(0, 8):
- grid.setPixel(x, y, iter%4 )
+ grid.setPixel(x, y, iter % 4 )
time.sleep(0.02)
-
-# 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
-
-# time.sleep(0.5)
-# grid.clear()
-# time.sleep(0.5)

0 comments on commit 5b3f89f

Please sign in to comment.