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

Commit 2c8254f

Browse files
committedMar 12, 2013
Merge pull request #4 from mprice64/master
Rudimentary color support, and some notes on possible bugs.
2 parents 8f4f12d + 98a5d16 commit 2c8254f

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
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)) )
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/python
2+
3+
import time
4+
import datetime
5+
from Adafruit_8x8 import ColorEightByEight
6+
7+
# ===========================================================================
8+
# 8x8 Pixel Example
9+
# ===========================================================================
10+
grid = ColorEightByEight(address=0x70)
11+
12+
print "Press CTRL+Z to exit"
13+
14+
iter = 0
15+
16+
# Continually update the 8x8 display one pixel at a time
17+
while(True):
18+
iter += 1
19+
20+
for x in range(0, 8):
21+
for y in range(0, 8):
22+
grid.setPixel(x, y, iter % 4 )
23+
time.sleep(0.02)

0 commit comments

Comments
 (0)