Library to drive a pair of Adafruit 16x8 led matrices (powered by Adafruit LED Backpack) rotated end to end and stuck together to make a larger matrix.
Dependencies: Adafruit_LEDBackpack
Dependents: Adafruit_LEDBackpack_32x8_App RubeGoldberg
Diff: Adafruit_32x8matrix.cpp
- Revision:
- 2:cdcd2d7d83c3
- Parent:
- 1:ed6764fbda54
--- a/Adafruit_32x8matrix.cpp Fri Nov 10 14:08:31 2017 -0600
+++ b/Adafruit_32x8matrix.cpp Mon Dec 11 19:22:54 2017 +0000
@@ -26,7 +26,6 @@
void Adafruit_32x8matrix::scrollText(char * buffer, uint8_t buf_len, uint8_t speed)
{
-
// code inspired by LOLShield library
int xoff=31;// set offset to the right end of the screen - must be signed
for(int i=0; i< (31 + buf_len*6 +10); i++){ //scrolling loop
@@ -63,3 +62,62 @@
_matrix2.clear();
}
+
+void Adafruit_32x8matrix::playText(char * buffer, uint8_t buf_len, uint8_t speed)
+{
+ char words[16][16]; //16 words max, 16 char max in each word
+ int word_count = 0;
+
+ for(int k=0; k<16; k++){ //for each word, up to 16
+ for(int j=0; j<16; j++){
+ words[k][j] = '\0'; //clear all chars
+ }
+ }
+
+ int k = 0; //word index
+ int m = 0; //char index in each word
+ for(int j=0; j<buf_len; j++){//loop over all of the chars in the text
+ if (buffer[j] == ' '){//if space, stop building the word up
+ //not required - words[k][m+1] = '\0'; //terminate the string
+ //printf("found word: %s\r\n",words[k]);
+ k++; //go to next word
+ m = 0;
+ }
+ else{
+ if(m < 16) { //limit chars to 16
+ words[k][m] = buffer[j]; //build up the string of chars to form words
+ m++; //got to next char
+ }
+ }
+ if(k >= 16){ //reached max words
+ break;
+ }
+
+ }
+ //last word may not have a space at the end that identifies it, so add one to the count
+ if(k < 16)
+ {
+ k++;
+ }
+
+ //k is the word count now
+ word_count = k;
+ // printf("words found = %d\r\n",word_count);
+ /* for(int n=0; n<k; n++){
+ printf("%s\r\n",words[n]);
+ }
+ */
+
+ //for each word in the string, show it
+ for(int p=0; p<word_count; p++){
+ if (strlen(words[p]) > 5) //can fit about 5 chars on the screen at once, if greater use scroll.
+ {
+ this->scrollText(words[p],strlen(words[p]), 100);
+ }
+ else{
+ this->showText(words[p],strlen(words[p]), 1);
+ }
+ }
+
+
+}
\ No newline at end of file