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

Rudimentary color support, and some notes on possible bugs. #4

Merged
merged 4 commits into from
Mar 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions Adafruit_LEDBackpack/Adafruit_8x8.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)) )
23 changes: 23 additions & 0 deletions Adafruit_LEDBackpack/ex_8x8_color_pixels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python

import time
import datetime
from Adafruit_8x8 import ColorEightByEight

# ===========================================================================
# 8x8 Pixel Example
# ===========================================================================
grid = ColorEightByEight(address=0x70)

print "Press CTRL+Z to exit"

iter = 0

# Continually update the 8x8 display one pixel at a time
while(True):
iter += 1

for x in range(0, 8):
for y in range(0, 8):
grid.setPixel(x, y, iter % 4 )
time.sleep(0.02)