Print a message to a custom LED matrix and play a song on a piezo buzzer.
Dependencies: Adafruit_32x8matrix
Revision 2:ffe5cf2557e3, committed 2016-12-22
- Comitter:
- maclobdell
- Date:
- Thu Dec 22 20:34:41 2016 +0000
- Parent:
- 1:dd1d1b64b9a5
- Child:
- 3:f9fbd8054caa
- Commit message:
- now able to scroll a string across both matrix (2 x 16) x 8 = 32 x 8
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Dec 21 18:25:03 2016 +0000
+++ b/main.cpp Thu Dec 22 20:34:41 2016 +0000
@@ -14,75 +14,37 @@
int main() {
-/* matrix[0].begin(0x70);
- //while(1)
-// {
- matrix[0].clear();
- for (int i = 0; i < 16; i++) {
- for (int j = 0; j < 8; j++) {
- matrix.drawPixel(i, j, LED_ON);
- matrix.writeDisplay(); // write the changes we just made to the display
- Thread::wait(10);
- }
- }
-
- matrix2.begin(0x71);
- matrix2.clear();
-
- for (int i = 0; i < 16; i++) {
- for (int j = 0; j < 8; j++) {
- matrix2.drawPixel(i, j, LED_ON);
- matrix2.writeDisplay(); // write the changes we just made to the display
- Thread::wait(10);
- }
- }
-
-*/
matrix2.begin(0x71);
matrix2.clear();
matrix2.writeDisplay();
-// matrix2.writeChar('A');
-// matrix2.writeDisplay();
-// Thread::wait(10);
-
+
matrix.begin(0x70);
matrix.clear();
matrix.writeDisplay();
-// matrix.writeChar('A');
-// matrix.writeChar('B');
-// matrix.writeChar('C');
-// matrix.writeDisplay();
- char buffer [50];
- sprintf (buffer, "Hello\0");
+ char buffer [50];
+ sprintf (buffer, "Hello\0");
scrollText(buffer,strlen(buffer));
-// }
}
void scrollText(char * buffer, uint8_t buf_len)
{
- uint8_t x_pos;
- uint8_t m;
- char c;
//pc.printf("buffer = %s, len = %d\r\n", buffer, buf_len);
-
- //Need to start at the end and draw backwards, each time scrolling one pixel to the right
- // then, stop when get to first character.
- //find example
/* code inspired by LOLShield library */
- int xoff=31;/* set offset to the right end of the screen*/
- for(int i=0; i<buf_len*5 +52; i++){ /*scrolling loop*/
- for(int j=0; j<buf_len; j++){ /*loop over all of the chars in the text*/
- if(xoff + j*6 <32)
+ 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*/
+ for(int j=0; j<buf_len; j++){ /*loop over all of the chars in the text*/
+ if(xoff > 15){
+ matrix2.drawChar(xoff + j*6 - 16, 0, buffer[j], 1, 0, 1);
+ matrix2.writeDisplay();
+ }else
{
matrix.drawChar(xoff + j*6, 0, buffer[j], 1, 0, 1);
matrix.writeDisplay();
- }else
- {
- matrix2.drawChar(xoff + j*6-32, 0, buffer[j], 1, 0, 1);
+ matrix2.drawChar(xoff + j*6 - 16, 0, buffer[j], 1, 0, 1);
matrix2.writeDisplay();
}
}
@@ -90,7 +52,5 @@
Thread::wait(70);
matrix.clear();
matrix2.clear();
- }
-
-
+ }
}