This is a library for the Adafruit LED Backpacks. This library works with the Adafruit Mini 8x8 and 16x8.

Dependents:   Adafruit_LEDBackpack_16x8_App Adafruit_32x8matrix

Fork of Adafruit_LEDBackpack by Luiz Hespanha

Files at this revision

API Documentation at this revision

Comitter:
maclobdell
Date:
Wed Dec 21 18:24:56 2016 +0000
Parent:
2:529bad55777e
Child:
4:b4ce71619694
Commit message:
initial commit. work in progress

Changed in this revision

Adafruit_GFX.cpp Show annotated file Show diff for this revision Revisions of this file
Adafruit_GFX.h Show annotated file Show diff for this revision Revisions of this file
Adafruit_LEDBackpack.cpp Show annotated file Show diff for this revision Revisions of this file
Adafruit_LEDBackpack.h Show annotated file Show diff for this revision Revisions of this file
--- a/Adafruit_GFX.cpp	Thu Dec 15 17:31:22 2016 +0000
+++ b/Adafruit_GFX.cpp	Wed Dec 21 18:24:56 2016 +0000
@@ -363,6 +363,10 @@
 
 size_t Adafruit_GFX::writeChar(uint8_t c)
 {
+    
+    //mpl
+    printf("entered writeChar \r\n");
+    
     if (c == '\n')
     {
         cursor_y += textsize*8;
@@ -386,13 +390,14 @@
 // draw a character
 void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size)
 {
+   
     if(
         (x >= _width) || // Clip right
         (y >= _height) || // Clip bottom
         ((x + 5 * size - 1) < 0) || // Clip left
         ((y + 8 * size - 1) < 0) // Clip top
         )
-    return;
+        return;
     
     for (int8_t i=0; i<6; i++ )
     {
--- a/Adafruit_GFX.h	Thu Dec 15 17:31:22 2016 +0000
+++ b/Adafruit_GFX.h	Wed Dec 21 18:24:56 2016 +0000
@@ -83,9 +83,11 @@
 #endif
 
     void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
+    //virtual void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
+    //virtual size_t writeChar(uint8_t);
     void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
     size_t writeChar(uint8_t);
-
+    
     int16_t width(void) { return _width; };
     int16_t height(void) { return _height; };
 
--- a/Adafruit_LEDBackpack.cpp	Thu Dec 15 17:31:22 2016 +0000
+++ b/Adafruit_LEDBackpack.cpp	Wed Dec 21 18:24:56 2016 +0000
@@ -25,6 +25,10 @@
 #include "mbed.h"
 #include "Adafruit_LEDBackpack.h"
 #include "Adafruit_GFX.h"
+#include "glcdfont.h"
+
+//mpl - something with stdio screwing things up.  need to define serial port to use for debug
+extern Serial pc;
 
 void Adafruit_LEDBackpack::setBrightness(uint8_t b) {
   if (b > 15) b = 15;
@@ -73,7 +77,7 @@
 }
 
 void Adafruit_LEDBackpack::clear(void) {
-  for (uint8_t i=0; i<8; i++) {
+  for (uint8_t i=0; i<16; i++) {
     displaybuffer[i] = 0;
   }
 }
@@ -111,6 +115,8 @@
   } else {
     displaybuffer[y] &= ~(1 << x);
   }
+  
+
 }
 
 
@@ -120,8 +126,8 @@
 void Adafruit_16x8matrix::drawPixel(int16_t x, int16_t y, uint16_t color) {
   if ((y < 0) || (y >= 8)) return;
   if ((x < 0) || (x >= 16)) return;
-
- // check rotation, move pixel around if necessary
+  
+ // check rotation, move pixel around if necessary 
   switch (getRotation()) {
   case 1:
     swap(x, y);
@@ -138,7 +144,7 @@
   }
 
   // wrap around the x
-  x += 15;
+  x += 16;
   x %= 16;
 
 
@@ -147,4 +153,98 @@
   } else {
     displaybuffer[y] &= ~(1 << x);
   }
+}
+
+size_t Adafruit_16x8matrix::writeChar(uint8_t c)
+{
+        
+    if (c == '\n')
+    {
+        cursor_y += textsize*8;
+        cursor_x = 0;
+    }
+    else if (c == '\r')
+        cursor_x = 0;
+    else
+    {
+        drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize);
+        cursor_x += textsize*6;
+       // if (wrap && (cursor_x > (_width - textsize*6)))
+       // {
+       //     cursor_y += textsize*8;
+       //     cursor_x = 0;
+        //}
+    }
+    return 1;
+}
+
+void Adafruit_16x8matrix::scrollChar(uint8_t c)
+{
+        
+    if (c == '\n')
+    {
+        cursor_y += textsize*8;
+        cursor_x = 0;
+    }
+    else if (c == '\r')
+        cursor_x = 0;
+    else
+    {
+        for(int i = 0; i < 16; i++)
+        {
+            drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize);
+            writeDisplay();
+            Thread::wait(100);
+            clear();
+            writeDisplay();
+            cursor_x++;
+        }    
+    }
+}
+
+// draw a character
+void Adafruit_16x8matrix::drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size)
+{
+  
+//allow clipping   
+//    if(
+//        (x >= _width) || // Clip right
+//        (y >= _height) || // Clip bottom
+//        ((x + 5 * size - 1) < 0) || // Clip left
+//        ((y + 8 * size - 1) < 0) // Clip top
+//        )
+//        return;
+    
+    for (int8_t i=0; i<6; i++ )
+    {
+        uint8_t line = 0;
+
+        if (i == 5) 
+            line = 0x0;
+        else 
+            line = font[(c*5)+i];
+            
+        for (int8_t j = 0; j<8; j++)
+        {
+            if (line & 0x1)
+            {
+                if (size == 1) // default size
+                    drawPixel(x+i, y+j, color);
+#ifdef WANT_ABSTRACTS
+                else // big size
+                    fillRect(x+(i*size), y+(j*size), size, size, color);
+#endif                    
+            }
+            else if (bg != color)
+            {
+                if (size == 1) // default size
+                    drawPixel(x+i, y+j, bg);
+#ifdef WANT_ABSTRACTS
+                else // big size
+                    fillRect(x+i*size, y+j*size, size, size, bg);
+#endif
+            }
+            line >>= 1;
+        }
+    }
 }
\ No newline at end of file
--- a/Adafruit_LEDBackpack.h	Thu Dec 15 17:31:22 2016 +0000
+++ b/Adafruit_LEDBackpack.h	Wed Dec 21 18:24:56 2016 +0000
@@ -53,7 +53,7 @@
   void writeDisplay(void);
   void clear(void);
 
-  uint16_t displaybuffer[8]; 
+  uint16_t displaybuffer[16]; 
 
   void init(uint8_t a);
 
@@ -78,6 +78,9 @@
   Adafruit_16x8matrix(I2C *i2c);
 
   void drawPixel(int16_t x, int16_t y, uint16_t color);
+    virtual void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
+    virtual size_t writeChar(uint8_t);
+  void scrollChar(uint8_t c);
 
  private:
 };
\ No newline at end of file