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

/media/uploads/maclobdell/austin_iot_lab.jpg

Files at this revision

API Documentation at this revision

Comitter:
maclobdell
Date:
Mon Dec 11 19:22:54 2017 +0000
Parent:
1:ed6764fbda54
Commit message:
added playText function which parses a sentence and either shows the individual words (for short words under 5 chars), or scrolls them for words equal to or greater than 5 chars. also updated mbed-os library.

Changed in this revision

Adafruit_32x8matrix.cpp Show annotated file Show diff for this revision Revisions of this file
Adafruit_32x8matrix.h Show annotated file Show diff for this revision Revisions of this file
diff -r ed6764fbda54 -r cdcd2d7d83c3 Adafruit_32x8matrix.cpp
--- 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
diff -r ed6764fbda54 -r cdcd2d7d83c3 Adafruit_32x8matrix.h
--- a/Adafruit_32x8matrix.h	Fri Nov 10 14:08:31 2017 -0600
+++ b/Adafruit_32x8matrix.h	Mon Dec 11 19:22:54 2017 +0000
@@ -16,7 +16,8 @@
     
     void scrollText(char * , uint8_t , uint8_t );
     void showText(char * , uint8_t , uint8_t );
-  
+    void playText(char * , uint8_t , uint8_t );
+   
 private:
     I2C *_i2c;
     Adafruit_16x8matrix _matrix;