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
Diff: Adafruit_LEDBackpack.cpp
- Revision:
- 3:b0ac557b5f0c
- Parent:
- 2:529bad55777e
--- 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