Print a message to a custom LED matrix and play a song on a piezo buzzer.
Dependencies: Adafruit_32x8matrix
main.cpp
- Committer:
- maclobdell
- Date:
- 2017-04-10
- Revision:
- 5:f2820d1efc08
- Parent:
- 4:8641e4da6744
File content as of revision 5:f2820d1efc08:
#include "mbed.h"
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
I2C i2c(D14, D15);
//notes and todos-
//need to make the quad display with text scroll into its own class
//220uA no leds on
//default brightness - rises to 20mA at short peak then back down when scrolling hello
//brightness = 1, rises to ~4mA at short peak then back down when scrolling hello
//mpl - something with stdio screwing things up. need to define serial port to use for debug
Serial pc (USBTX,USBRX);
Adafruit_16x8matrix matrix = Adafruit_16x8matrix(&i2c);
Adafruit_16x8matrix matrix2 = Adafruit_16x8matrix(&i2c);
void scrollText(char * buffer, uint8_t buf_len, uint8_t speed);
void showText(char * buffer, uint8_t buf_len, uint8_t duration);
void myidlethread(void);
int main() {
matrix2.begin(0x71);
matrix2.setBrightness(1);
matrix2.setRotation(2);
matrix2.clear();
matrix2.writeDisplay();
matrix.begin(0x70);
matrix.setBrightness(1);
matrix.clear();
matrix.writeDisplay();
char buffer [50];
sprintf(buffer, "This\0");
showText(buffer,strlen(buffer), 1);
sprintf(buffer, "is\0");
showText(buffer,strlen(buffer), 1);
sprintf(buffer, "the\0");
showText(buffer,strlen(buffer), 1);
sprintf (buffer, "IoT Lab\0");
while(1)
{
scrollText(buffer,strlen(buffer), 100);
Thread::attach_idle_hook (myidlethread);
Thread::wait(10000);
}
}
void myidlethread(void)
{
sleep(); //go to sleep, wait for an interrupt
}
void scrollText(char * buffer, uint8_t buf_len, uint8_t speed)
{
//pc.printf("buffer = %s, len = %d\r\n", buffer, buf_len);
/* 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*/
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);
}else
{
matrix.drawChar(xoff + j*6, 0, buffer[j], 1, 0, 1);
matrix2.drawChar(xoff + j*6 - 16, 0, buffer[j], 1, 0, 1);
}
}
xoff--; /* decrement x offset*/
matrix.writeDisplay();
matrix2.writeDisplay();
Thread::wait(2000/speed);
matrix.clear();
matrix2.clear();
}
}
void showText(char * buffer, uint8_t buf_len, uint8_t duration)
{
for(int j=0; j<buf_len; j++){ /*loop over all of the chars in the text*/
matrix.drawChar(j*6, 0, buffer[j], 1, 0, 1);
matrix2.drawChar(j*6 - 16, 0, buffer[j], 1, 0, 1);
}
matrix.writeDisplay();
matrix2.writeDisplay();
Thread::wait(1000*duration);
matrix.clear();
matrix2.clear();
}