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
This project uses two 16x8 1.2" LED Matrix + Backpacks stuck together to make a 32x8 double-length matrix.
main.cpp@5:f2820d1efc08, 2017-04-10 (annotated)
- Committer:
- maclobdell
- Date:
- Mon Apr 10 14:43:42 2017 +0000
- Revision:
- 5:f2820d1efc08
- Parent:
- 4:8641e4da6744
wait to display (send data) until frame buffer written. speeds performance significantly. Also added function to show text without scroll
Who changed what in which revision?
User | Revision | Line number | New 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 | 5:f2820d1efc08 | 21 | void showText(char * buffer, uint8_t buf_len, uint8_t duration); |
maclobdell | 5:f2820d1efc08 | 22 | |
maclobdell | 4:8641e4da6744 | 23 | void myidlethread(void); |
maclobdell | 1:dd1d1b64b9a5 | 24 | |
maclobdell | 0:2eec8a9428ea | 25 | int main() { |
maclobdell | 1:dd1d1b64b9a5 | 26 | |
maclobdell | 1:dd1d1b64b9a5 | 27 | matrix2.begin(0x71); |
maclobdell | 4:8641e4da6744 | 28 | matrix2.setBrightness(1); |
maclobdell | 4:8641e4da6744 | 29 | matrix2.setRotation(2); |
maclobdell | 4:8641e4da6744 | 30 | |
maclobdell | 1:dd1d1b64b9a5 | 31 | matrix2.clear(); |
maclobdell | 1:dd1d1b64b9a5 | 32 | matrix2.writeDisplay(); |
maclobdell | 2:ffe5cf2557e3 | 33 | |
maclobdell | 1:dd1d1b64b9a5 | 34 | matrix.begin(0x70); |
maclobdell | 4:8641e4da6744 | 35 | matrix.setBrightness(1); |
maclobdell | 4:8641e4da6744 | 36 | |
maclobdell | 1:dd1d1b64b9a5 | 37 | matrix.clear(); |
maclobdell | 1:dd1d1b64b9a5 | 38 | matrix.writeDisplay(); |
maclobdell | 1:dd1d1b64b9a5 | 39 | |
maclobdell | 2:ffe5cf2557e3 | 40 | char buffer [50]; |
maclobdell | 5:f2820d1efc08 | 41 | |
maclobdell | 5:f2820d1efc08 | 42 | sprintf(buffer, "This\0"); |
maclobdell | 5:f2820d1efc08 | 43 | showText(buffer,strlen(buffer), 1); |
maclobdell | 5:f2820d1efc08 | 44 | sprintf(buffer, "is\0"); |
maclobdell | 5:f2820d1efc08 | 45 | showText(buffer,strlen(buffer), 1); |
maclobdell | 5:f2820d1efc08 | 46 | sprintf(buffer, "the\0"); |
maclobdell | 5:f2820d1efc08 | 47 | showText(buffer,strlen(buffer), 1); |
maclobdell | 4:8641e4da6744 | 48 | sprintf (buffer, "IoT Lab\0"); |
maclobdell | 5:f2820d1efc08 | 49 | |
maclobdell | 4:8641e4da6744 | 50 | while(1) |
maclobdell | 4:8641e4da6744 | 51 | { |
maclobdell | 5:f2820d1efc08 | 52 | scrollText(buffer,strlen(buffer), 100); |
maclobdell | 4:8641e4da6744 | 53 | |
maclobdell | 4:8641e4da6744 | 54 | Thread::attach_idle_hook (myidlethread); |
maclobdell | 4:8641e4da6744 | 55 | |
maclobdell | 4:8641e4da6744 | 56 | Thread::wait(10000); |
maclobdell | 4:8641e4da6744 | 57 | } |
maclobdell | 1:dd1d1b64b9a5 | 58 | |
maclobdell | 1:dd1d1b64b9a5 | 59 | } |
maclobdell | 1:dd1d1b64b9a5 | 60 | |
maclobdell | 4:8641e4da6744 | 61 | void myidlethread(void) |
maclobdell | 4:8641e4da6744 | 62 | { |
maclobdell | 4:8641e4da6744 | 63 | sleep(); //go to sleep, wait for an interrupt |
maclobdell | 4:8641e4da6744 | 64 | |
maclobdell | 4:8641e4da6744 | 65 | } |
maclobdell | 4:8641e4da6744 | 66 | |
maclobdell | 4:8641e4da6744 | 67 | |
maclobdell | 4:8641e4da6744 | 68 | void scrollText(char * buffer, uint8_t buf_len, uint8_t speed) |
maclobdell | 1:dd1d1b64b9a5 | 69 | { |
maclobdell | 1:dd1d1b64b9a5 | 70 | |
maclobdell | 1:dd1d1b64b9a5 | 71 | //pc.printf("buffer = %s, len = %d\r\n", buffer, buf_len); |
maclobdell | 1:dd1d1b64b9a5 | 72 | |
maclobdell | 1:dd1d1b64b9a5 | 73 | /* code inspired by LOLShield library */ |
maclobdell | 2:ffe5cf2557e3 | 74 | int xoff=31;/* set offset to the right end of the screen - must be signed*/ |
maclobdell | 2:ffe5cf2557e3 | 75 | for(int i=0; i< (31 + buf_len*6 +10); i++){ /*scrolling loop*/ |
maclobdell | 2:ffe5cf2557e3 | 76 | for(int j=0; j<buf_len; j++){ /*loop over all of the chars in the text*/ |
maclobdell | 2:ffe5cf2557e3 | 77 | if(xoff > 15){ |
maclobdell | 2:ffe5cf2557e3 | 78 | matrix2.drawChar(xoff + j*6 - 16, 0, buffer[j], 1, 0, 1); |
maclobdell | 5:f2820d1efc08 | 79 | |
maclobdell | 2:ffe5cf2557e3 | 80 | }else |
maclobdell | 1:dd1d1b64b9a5 | 81 | { |
maclobdell | 1:dd1d1b64b9a5 | 82 | matrix.drawChar(xoff + j*6, 0, buffer[j], 1, 0, 1); |
maclobdell | 2:ffe5cf2557e3 | 83 | matrix2.drawChar(xoff + j*6 - 16, 0, buffer[j], 1, 0, 1); |
maclobdell | 1:dd1d1b64b9a5 | 84 | } |
maclobdell | 1:dd1d1b64b9a5 | 85 | } |
maclobdell | 1:dd1d1b64b9a5 | 86 | xoff--; /* decrement x offset*/ |
maclobdell | 5:f2820d1efc08 | 87 | matrix.writeDisplay(); |
maclobdell | 5:f2820d1efc08 | 88 | matrix2.writeDisplay(); |
maclobdell | 5:f2820d1efc08 | 89 | Thread::wait(2000/speed); |
maclobdell | 1:dd1d1b64b9a5 | 90 | matrix.clear(); |
maclobdell | 1:dd1d1b64b9a5 | 91 | matrix2.clear(); |
maclobdell | 2:ffe5cf2557e3 | 92 | } |
maclobdell | 1:dd1d1b64b9a5 | 93 | } |
maclobdell | 5:f2820d1efc08 | 94 | |
maclobdell | 5:f2820d1efc08 | 95 | |
maclobdell | 5:f2820d1efc08 | 96 | void showText(char * buffer, uint8_t buf_len, uint8_t duration) |
maclobdell | 5:f2820d1efc08 | 97 | { |
maclobdell | 5:f2820d1efc08 | 98 | for(int j=0; j<buf_len; j++){ /*loop over all of the chars in the text*/ |
maclobdell | 5:f2820d1efc08 | 99 | matrix.drawChar(j*6, 0, buffer[j], 1, 0, 1); |
maclobdell | 5:f2820d1efc08 | 100 | matrix2.drawChar(j*6 - 16, 0, buffer[j], 1, 0, 1); |
maclobdell | 5:f2820d1efc08 | 101 | } |
maclobdell | 5:f2820d1efc08 | 102 | matrix.writeDisplay(); |
maclobdell | 5:f2820d1efc08 | 103 | matrix2.writeDisplay(); |
maclobdell | 5:f2820d1efc08 | 104 | Thread::wait(1000*duration); |
maclobdell | 5:f2820d1efc08 | 105 | matrix.clear(); |
maclobdell | 5:f2820d1efc08 | 106 | matrix2.clear(); |
maclobdell | 5:f2820d1efc08 | 107 | |
maclobdell | 5:f2820d1efc08 | 108 | } |