Example application for 16x8 Adafruit LED Backpacks.

Dependencies:   Adafruit_LEDBackpack

Committer:
maclobdell
Date:
Thu Dec 22 20:42:03 2016 +0000
Revision:
3:f9fbd8054caa
Parent:
2:ffe5cf2557e3
now able to scroll text across full 32 x 8 matrix (made of two 16 x 8 Adafruit LED matrix backpacks).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maclobdell 0:2eec8a9428ea 1 #include "mbed.h"
maclobdell 0:2eec8a9428ea 2 #include "Adafruit_LEDBackpack.h"
maclobdell 0:2eec8a9428ea 3 #include "Adafruit_GFX.h"
maclobdell 0:2eec8a9428ea 4
maclobdell 0:2eec8a9428ea 5 I2C i2c(D14, D15);
maclobdell 1:dd1d1b64b9a5 6
maclobdell 1:dd1d1b64b9a5 7 //mpl - something with stdio screwing things up. need to define serial port to use for debug
maclobdell 1:dd1d1b64b9a5 8 Serial pc (USBTX,USBRX);
maclobdell 1:dd1d1b64b9a5 9
maclobdell 0:2eec8a9428ea 10 Adafruit_16x8matrix matrix = Adafruit_16x8matrix(&i2c);
maclobdell 1:dd1d1b64b9a5 11 Adafruit_16x8matrix matrix2 = Adafruit_16x8matrix(&i2c);
maclobdell 1:dd1d1b64b9a5 12
maclobdell 1:dd1d1b64b9a5 13 void scrollText(char * buffer, uint8_t buf_len);
maclobdell 1:dd1d1b64b9a5 14
maclobdell 0:2eec8a9428ea 15 int main() {
maclobdell 1:dd1d1b64b9a5 16
maclobdell 1:dd1d1b64b9a5 17 matrix2.begin(0x71);
maclobdell 1:dd1d1b64b9a5 18 matrix2.clear();
maclobdell 1:dd1d1b64b9a5 19 matrix2.writeDisplay();
maclobdell 2:ffe5cf2557e3 20
maclobdell 1:dd1d1b64b9a5 21 matrix.begin(0x70);
maclobdell 1:dd1d1b64b9a5 22 matrix.clear();
maclobdell 1:dd1d1b64b9a5 23 matrix.writeDisplay();
maclobdell 1:dd1d1b64b9a5 24
maclobdell 2:ffe5cf2557e3 25 char buffer [50];
maclobdell 2:ffe5cf2557e3 26 sprintf (buffer, "Hello\0");
maclobdell 1:dd1d1b64b9a5 27 scrollText(buffer,strlen(buffer));
maclobdell 1:dd1d1b64b9a5 28
maclobdell 1:dd1d1b64b9a5 29 }
maclobdell 1:dd1d1b64b9a5 30
maclobdell 1:dd1d1b64b9a5 31 void scrollText(char * buffer, uint8_t buf_len)
maclobdell 1:dd1d1b64b9a5 32 {
maclobdell 1:dd1d1b64b9a5 33
maclobdell 1:dd1d1b64b9a5 34 //pc.printf("buffer = %s, len = %d\r\n", buffer, buf_len);
maclobdell 1:dd1d1b64b9a5 35
maclobdell 1:dd1d1b64b9a5 36 /* code inspired by LOLShield library */
maclobdell 2:ffe5cf2557e3 37 int xoff=31;/* set offset to the right end of the screen - must be signed*/
maclobdell 2:ffe5cf2557e3 38 for(int i=0; i< (31 + buf_len*6 +10); i++){ /*scrolling loop*/
maclobdell 2:ffe5cf2557e3 39 for(int j=0; j<buf_len; j++){ /*loop over all of the chars in the text*/
maclobdell 2:ffe5cf2557e3 40 if(xoff > 15){
maclobdell 2:ffe5cf2557e3 41 matrix2.drawChar(xoff + j*6 - 16, 0, buffer[j], 1, 0, 1);
maclobdell 2:ffe5cf2557e3 42 matrix2.writeDisplay();
maclobdell 2:ffe5cf2557e3 43 }else
maclobdell 1:dd1d1b64b9a5 44 {
maclobdell 1:dd1d1b64b9a5 45 matrix.drawChar(xoff + j*6, 0, buffer[j], 1, 0, 1);
maclobdell 1:dd1d1b64b9a5 46 matrix.writeDisplay();
maclobdell 2:ffe5cf2557e3 47 matrix2.drawChar(xoff + j*6 - 16, 0, buffer[j], 1, 0, 1);
maclobdell 1:dd1d1b64b9a5 48 matrix2.writeDisplay();
maclobdell 1:dd1d1b64b9a5 49 }
maclobdell 1:dd1d1b64b9a5 50 }
maclobdell 1:dd1d1b64b9a5 51 xoff--; /* decrement x offset*/
maclobdell 1:dd1d1b64b9a5 52 Thread::wait(70);
maclobdell 1:dd1d1b64b9a5 53 matrix.clear();
maclobdell 1:dd1d1b64b9a5 54 matrix2.clear();
maclobdell 2:ffe5cf2557e3 55 }
maclobdell 1:dd1d1b64b9a5 56 }