Example application for 16x8 Adafruit LED Backpacks.
Dependencies: Adafruit_LEDBackpack
main.cpp
- Committer:
- maclobdell
- Date:
- 2016-12-21
- Revision:
- 1:dd1d1b64b9a5
- Parent:
- 0:2eec8a9428ea
- Child:
- 2:ffe5cf2557e3
File content as of revision 1:dd1d1b64b9a5:
#include "mbed.h"
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
I2C i2c(D14, D15);
//mpl - something with stdio screwing things up. need to define serial port to use for debug
Serial pc (USBTX,USBRX);
Adafruit_16x8matrix matrix = Adafruit_16x8matrix(&i2c);
Adafruit_16x8matrix matrix2 = Adafruit_16x8matrix(&i2c);
void scrollText(char * buffer, uint8_t buf_len);
int main() {
/* matrix[0].begin(0x70);
//while(1)
// {
matrix[0].clear();
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 8; j++) {
matrix.drawPixel(i, j, LED_ON);
matrix.writeDisplay(); // write the changes we just made to the display
Thread::wait(10);
}
}
matrix2.begin(0x71);
matrix2.clear();
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 8; j++) {
matrix2.drawPixel(i, j, LED_ON);
matrix2.writeDisplay(); // write the changes we just made to the display
Thread::wait(10);
}
}
*/
matrix2.begin(0x71);
matrix2.clear();
matrix2.writeDisplay();
// matrix2.writeChar('A');
// matrix2.writeDisplay();
// Thread::wait(10);
matrix.begin(0x70);
matrix.clear();
matrix.writeDisplay();
// matrix.writeChar('A');
// matrix.writeChar('B');
// matrix.writeChar('C');
// matrix.writeDisplay();
char buffer [50];
sprintf (buffer, "Hello\0");
scrollText(buffer,strlen(buffer));
// }
}
void scrollText(char * buffer, uint8_t buf_len)
{
uint8_t x_pos;
uint8_t m;
char c;
//pc.printf("buffer = %s, len = %d\r\n", buffer, buf_len);
//Need to start at the end and draw backwards, each time scrolling one pixel to the right
// then, stop when get to first character.
//find example
/* code inspired by LOLShield library */
int xoff=31;/* set offset to the right end of the screen*/
for(int i=0; i<buf_len*5 +52; i++){ /*scrolling loop*/
for(int j=0; j<buf_len; j++){ /*loop over all of the chars in the text*/
if(xoff + j*6 <32)
{
matrix.drawChar(xoff + j*6, 0, buffer[j], 1, 0, 1);
matrix.writeDisplay();
}else
{
matrix2.drawChar(xoff + j*6-32, 0, buffer[j], 1, 0, 1);
matrix2.writeDisplay();
}
}
xoff--; /* decrement x offset*/
Thread::wait(70);
matrix.clear();
matrix2.clear();
}
}