|
1 | 1 | #!/usr/bin/python
|
| 2 | +# Updated to allow for scrolling text with the Adafruit_GFX.py library |
| 3 | +# ColorEightByEight not updated yet. |
2 | 4 |
|
3 |
| -import time |
4 |
| -import datetime |
5 | 5 | from Adafruit_LEDBackpack import LEDBackpack
|
6 | 6 |
|
7 | 7 | # ===========================================================================
|
8 | 8 | # 8x8 Pixel Display
|
9 | 9 | # ===========================================================================
|
10 | 10 |
|
11 |
| -class EightByEight: |
12 |
| - disp = None |
| 11 | +class EightByEight(LEDBackpack): |
| 12 | + #disp = None |
| 13 | + rotation = None |
13 | 14 |
|
14 | 15 | # Constructor
|
15 | 16 | def __init__(self, address=0x70, debug=False):
|
16 | 17 | if (debug):
|
17 | 18 | print "Initializing a new instance of LEDBackpack at 0x%02X" % address
|
18 |
| - self.disp = LEDBackpack(address=address, debug=debug) |
| 19 | + LEDBackpack.__init__(self, 8, 8, address, debug) |
| 20 | + self.rotation = 0 |
19 | 21 |
|
20 | 22 | def writeRowRaw(self, charNumber, value):
|
21 |
| - "Sets a row of pixels using a raw 16-bit value" |
| 23 | + #"Sets a row of pixels using a raw 16-bit value" |
22 | 24 | if (charNumber > 7):
|
23 | 25 | return
|
24 | 26 | # Set the appropriate row
|
25 |
| - self.disp.setBufferRow(charNumber, value) |
| 27 | + self.setBufferRow(charNumber, value) |
26 | 28 |
|
27 | 29 | def clearPixel(self, x, y):
|
28 |
| - "A wrapper function to clear pixels (purely cosmetic)" |
| 30 | + #"A wrapper function to clear pixels (purely cosmetic)" |
29 | 31 | self.setPixel(x, y, 0)
|
30 | 32 |
|
31 |
| - def setPixel(self, x, y, color=1): |
32 |
| - "Sets a single pixel" |
33 |
| - if (x >= 8): |
| 33 | + def drawPixel(self, x, y, color=1): |
| 34 | + #"Sets a single pixel" |
| 35 | + if ((y < 0) or (y >= 8)): |
34 | 36 | return
|
35 |
| - if (y >= 8): |
| 37 | + if ((x < 0) or (x >= 8)): |
36 | 38 | return
|
| 39 | + |
| 40 | + # Added rotation code 4/16/13 - RH |
| 41 | + if self.rotation == 1: |
| 42 | + x, y = self.swap(x, y) |
| 43 | + x = 8 - x - 1 |
| 44 | + elif self.rotation == 2: |
| 45 | + x = 8 - x - 1 |
| 46 | + y = 8 - y - 1 |
| 47 | + elif self.rotation == 3: |
| 48 | + x, y = self.swap(x, y) |
| 49 | + y = 8 - y - 1 |
| 50 | + |
37 | 51 | 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.
|
38 | 52 | x %= 8
|
39 | 53 | # Set the appropriate pixel
|
40 |
| - buffer = self.disp.getBuffer() |
| 54 | + buffer = self.getBuffer() |
41 | 55 | if (color):
|
42 |
| - self.disp.setBufferRow(y, buffer[y] | 1 << x) |
43 |
| - else: |
44 |
| - self.disp.setBufferRow(y, buffer[y] & ~(1 << x)) |
| 56 | + self.setBufferRow(y, buffer[y] | 1 << x, False) # disable update option to determine if writeDisplay() is called when |
| 57 | + else: # writing a bunch of pixels. Speeds things up dramatically when scrolling |
| 58 | + self.setBufferRow(y, buffer[y] & ~(1 << x), False) # text on multiple matrices. Call writeDisplay() after updating buffer. |
| 59 | + |
| 60 | + # Used to rotate display 4/16/13 - RH |
| 61 | + # Corrected for dual output 6/5/13 - RH |
| 62 | + def swap(self, x, y): |
| 63 | + temp = x |
| 64 | + x = y |
| 65 | + y = temp |
| 66 | + return (x, y) |
45 | 67 |
|
46 |
| - def clear(self): |
47 |
| - "Clears the entire display" |
48 |
| - self.disp.clear() |
| 68 | + # Added 6/3/13 - RH |
| 69 | + def printMessage(self, text): |
| 70 | + for letter in range(0, len(text)): |
| 71 | + self.write(text[letter]) |
| 72 | + if (self.debug): |
| 73 | + print(text[letter]) |
49 | 74 |
|
50 | 75 | class ColorEightByEight(EightByEight):
|
51 | 76 | def setPixel(self, x, y, color=1):
|
52 |
| - "Sets a single pixel" |
| 77 | + #"Sets a single pixel" |
53 | 78 | if (x >= 8):
|
54 | 79 | return
|
55 | 80 | if (y >= 8):
|
|
0 commit comments