From 0b56d5775849439e24b7b865912d902be13662e7 Mon Sep 17 00:00:00 2001 From: Benjamin Shockley Date: Mon, 26 Oct 2015 08:07:44 -0700 Subject: [PATCH 1/4] Create Adafruit_16x8.py Created a python script for the Adafruit 16x8 LED backpack. --- Adafruit_LEDBackpack/Adafruit_16x8.py | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Adafruit_LEDBackpack/Adafruit_16x8.py diff --git a/Adafruit_LEDBackpack/Adafruit_16x8.py b/Adafruit_LEDBackpack/Adafruit_16x8.py new file mode 100644 index 00000000..1f850d57 --- /dev/null +++ b/Adafruit_LEDBackpack/Adafruit_16x8.py @@ -0,0 +1,48 @@ +#!/usr/bin/python + +import time +import datetime +from Adafruit_LEDBackpack import LEDBackpack + +# =========================================================================== +# 16x8 Pixel Display +# =========================================================================== + +class SixteenByEight: + disp = None + + # Constructor + def __init__(self, address=0x70, debug=False): + if (debug): + print "Initializing a new instance of LEDBackpack at 0x%02X" % address + self.disp = LEDBackpack(address=address, debug=debug) + + def writeRowRaw(self, charNumber, value): + "Sets a row of pixels using a raw 16-bit value" + if (charNumber > 7): + return + # Set the appropriate row + self.disp.setBufferRow(charNumber, value) + + def clearPixel(self, x, y): + "A wrapper function to clear pixels (purely cosmetic)" + self.setPixel(x, y, 0) + + def setPixel(self, x, y, color=1): + "Sets a single pixel" + if (x >= 16): + return + if (y >= 8): + return + x += 16 # 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 %= 16 + # Set the appropriate pixel + buffer = self.disp.getBuffer() + if (color): + self.disp.setBufferRow(y, buffer[y] | 1 << x) + else: + self.disp.setBufferRow(y, buffer[y] & ~(1 << x)) + + def clear(self): + "Clears the entire display" + self.disp.clear() From a2daeea0e475d030cf7a772d11a72d065703bc30 Mon Sep 17 00:00:00 2001 From: Benjamin Shockley Date: Mon, 26 Oct 2015 08:10:10 -0700 Subject: [PATCH 2/4] Create ex_16x8_pixels.py Example script using the 16x8 backpack. --- Adafruit_LEDBackpack/ex_16x8_pixels.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Adafruit_LEDBackpack/ex_16x8_pixels.py diff --git a/Adafruit_LEDBackpack/ex_16x8_pixels.py b/Adafruit_LEDBackpack/ex_16x8_pixels.py new file mode 100644 index 00000000..789a94c0 --- /dev/null +++ b/Adafruit_LEDBackpack/ex_16x8_pixels.py @@ -0,0 +1,22 @@ +#!/usr/bin/python + +import time +import datetime +from Adafruit_16x8 import SixteenByEight + +# =========================================================================== +# 16x8 Pixel Example +# =========================================================================== +grid = SixteenByEight(address=0x70) + +print "Press CTRL+Z to exit" + +# Continually update the 16x8 display one pixel at a time +while(True): + for x in range(0, 8): + for y in range(0, 16): + grid.setPixel(x, y) + time.sleep(0.05) + time.sleep(0.5) + grid.clear() + time.sleep(0.5) From 02a697e29e9a2c8b92068224dcf5edcd243bab5d Mon Sep 17 00:00:00 2001 From: Benjamin Shockley Date: Tue, 27 Oct 2015 17:23:34 -0700 Subject: [PATCH 3/4] Exchanged x and y ranges Fixed x and y range error. --- Adafruit_LEDBackpack/ex_16x8_pixels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_LEDBackpack/ex_16x8_pixels.py b/Adafruit_LEDBackpack/ex_16x8_pixels.py index 789a94c0..2dbcad36 100644 --- a/Adafruit_LEDBackpack/ex_16x8_pixels.py +++ b/Adafruit_LEDBackpack/ex_16x8_pixels.py @@ -13,8 +13,8 @@ # Continually update the 16x8 display one pixel at a time while(True): - for x in range(0, 8): - for y in range(0, 16): + for x in range(0, 16): + for y in range(0, 8): grid.setPixel(x, y) time.sleep(0.05) time.sleep(0.5) From b1cc8f2245eb023493f08f4cbda4372baf8b9868 Mon Sep 17 00:00:00 2001 From: Benjamin Shockley Date: Tue, 24 Nov 2015 09:44:52 -0700 Subject: [PATCH 4/4] Update README.md Added information about this specific fork. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 8f342a3a..b22493ef 100644 --- a/README.md +++ b/README.md @@ -43,3 +43,11 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +##Shockley Fork + +This fork has added example code for a 16x8 LED matrix. In doing so, two additional python files were added: +ex_16x8_pixels.py +Adafruit_16x8.py + +These files can be used to demonstrate using a 16x8 LED matrix, such as [item # 2054 available at Adafruit.com.](http://www.adafruit.com/products/2054)