Example application for two 16x8 Adafruit LED Backpacks to make a 32 x 8 matrix.

Dependencies:   Adafruit_32x8matrix

Fork of Adafruit_LEDBackpack_16x8_App by Mac Lobdell

/media/uploads/maclobdell/austin_iot_lab.jpg

This project uses two 16x8 1.2" LED Matrix + Backpacks stuck together to make a 32x8 double-length matrix.

Committer:
maclobdell
Date:
Sat Apr 08 02:57:54 2017 +0000
Revision:
4:8641e4da6744
Parent:
2:ffe5cf2557e3
Child:
5:f2820d1efc08
Child:
6:8d2eb79a4baf
add scroll speed, set brightness and rotation, sleep when idle, scroll every 10 seconds;

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 4:8641e4da6744 7 //notes and todos-
maclobdell 4:8641e4da6744 8 //need to make the quad display with text scroll into its own class
maclobdell 4:8641e4da6744 9
maclobdell 4:8641e4da6744 10 //220uA no leds on
maclobdell 4:8641e4da6744 11 //default brightness - rises to 20mA at short peak then back down when scrolling hello
maclobdell 4:8641e4da6744 12 //brightness = 1, rises to ~4mA at short peak then back down when scrolling hello
maclobdell 4:8641e4da6744 13
maclobdell 1:dd1d1b64b9a5 14 //mpl - something with stdio screwing things up. need to define serial port to use for debug
maclobdell 1:dd1d1b64b9a5 15 Serial pc (USBTX,USBRX);
maclobdell 1:dd1d1b64b9a5 16
maclobdell 0:2eec8a9428ea 17 Adafruit_16x8matrix matrix = Adafruit_16x8matrix(&i2c);
maclobdell 1:dd1d1b64b9a5 18 Adafruit_16x8matrix matrix2 = Adafruit_16x8matrix(&i2c);
maclobdell 1:dd1d1b64b9a5 19
maclobdell 4:8641e4da6744 20 void scrollText(char * buffer, uint8_t buf_len, uint8_t speed);
maclobdell 4:8641e4da6744 21 void myidlethread(void);
maclobdell 1:dd1d1b64b9a5 22
maclobdell 0:2eec8a9428ea 23 int main() {
maclobdell 1:dd1d1b64b9a5 24
maclobdell 1:dd1d1b64b9a5 25 matrix2.begin(0x71);
maclobdell 4:8641e4da6744 26 matrix2.setBrightness(1);
maclobdell 4:8641e4da6744 27 matrix2.setRotation(2);
maclobdell 4:8641e4da6744 28
maclobdell 1:dd1d1b64b9a5 29 matrix2.clear();
maclobdell 1:dd1d1b64b9a5 30 matrix2.writeDisplay();
maclobdell 2:ffe5cf2557e3 31
maclobdell 1:dd1d1b64b9a5 32 matrix.begin(0x70);
maclobdell 4:8641e4da6744 33 matrix.setBrightness(1);
maclobdell 4:8641e4da6744 34
maclobdell 1:dd1d1b64b9a5 35 matrix.clear();
maclobdell 1:dd1d1b64b9a5 36 matrix.writeDisplay();
maclobdell 1:dd1d1b64b9a5 37
maclobdell 2:ffe5cf2557e3 38 char buffer [50];
maclobdell 4:8641e4da6744 39 sprintf (buffer, "IoT Lab\0");
maclobdell 4:8641e4da6744 40
maclobdell 4:8641e4da6744 41 while(1)
maclobdell 4:8641e4da6744 42 {
maclobdell 4:8641e4da6744 43 scrollText(buffer,strlen(buffer), 1000);
maclobdell 4:8641e4da6744 44
maclobdell 4:8641e4da6744 45 Thread::attach_idle_hook (myidlethread);
maclobdell 4:8641e4da6744 46
maclobdell 4:8641e4da6744 47 Thread::wait(10000);
maclobdell 4:8641e4da6744 48 }
maclobdell 1:dd1d1b64b9a5 49
maclobdell 1:dd1d1b64b9a5 50 }
maclobdell 1:dd1d1b64b9a5 51
maclobdell 4:8641e4da6744 52 void myidlethread(void)
maclobdell 4:8641e4da6744 53 {
maclobdell 4:8641e4da6744 54 sleep(); //go to sleep, wait for an interrupt
maclobdell 4:8641e4da6744 55
maclobdell 4:8641e4da6744 56 }
maclobdell 4:8641e4da6744 57
maclobdell 4:8641e4da6744 58
maclobdell 4:8641e4da6744 59 void scrollText(char * buffer, uint8_t buf_len, uint8_t speed)
maclobdell 1:dd1d1b64b9a5 60 {
maclobdell 1:dd1d1b64b9a5 61
maclobdell 1:dd1d1b64b9a5 62 //pc.printf("buffer = %s, len = %d\r\n", buffer, buf_len);
maclobdell 1:dd1d1b64b9a5 63
maclobdell 1:dd1d1b64b9a5 64 /* code inspired by LOLShield library */
maclobdell 2:ffe5cf2557e3 65 int xoff=31;/* set offset to the right end of the screen - must be signed*/
maclobdell 2:ffe5cf2557e3 66 for(int i=0; i< (31 + buf_len*6 +10); i++){ /*scrolling loop*/
maclobdell 2:ffe5cf2557e3 67 for(int j=0; j<buf_len; j++){ /*loop over all of the chars in the text*/
maclobdell 2:ffe5cf2557e3 68 if(xoff > 15){
maclobdell 2:ffe5cf2557e3 69 matrix2.drawChar(xoff + j*6 - 16, 0, buffer[j], 1, 0, 1);
maclobdell 2:ffe5cf2557e3 70 matrix2.writeDisplay();
maclobdell 2:ffe5cf2557e3 71 }else
maclobdell 1:dd1d1b64b9a5 72 {
maclobdell 1:dd1d1b64b9a5 73 matrix.drawChar(xoff + j*6, 0, buffer[j], 1, 0, 1);
maclobdell 1:dd1d1b64b9a5 74 matrix.writeDisplay();
maclobdell 2:ffe5cf2557e3 75 matrix2.drawChar(xoff + j*6 - 16, 0, buffer[j], 1, 0, 1);
maclobdell 1:dd1d1b64b9a5 76 matrix2.writeDisplay();
maclobdell 1:dd1d1b64b9a5 77 }
maclobdell 1:dd1d1b64b9a5 78 }
maclobdell 1:dd1d1b64b9a5 79 xoff--; /* decrement x offset*/
maclobdell 4:8641e4da6744 80 Thread::wait(1000/speed);
maclobdell 1:dd1d1b64b9a5 81 matrix.clear();
maclobdell 1:dd1d1b64b9a5 82 matrix2.clear();
maclobdell 2:ffe5cf2557e3 83 }
maclobdell 1:dd1d1b64b9a5 84 }