Print a message to a custom LED matrix and play a song on a piezo buzzer.
Dependencies: Adafruit_32x8matrix
Revision 6:8d2eb79a4baf, committed 2017-06-28
- Comitter:
- maclobdell
- Date:
- Wed Jun 28 19:27:51 2017 +0000
- Parent:
- 4:8641e4da6744
- Child:
- 7:1bd79d71396a
- Commit message:
- create class for combined matrix with two 16 x 8 matrices stuck together
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Adafruit_32x8matrix.cpp Wed Jun 28 19:27:51 2017 +0000
@@ -0,0 +1,66 @@
+#include "mbed.h"
+
+#include "Adafruit_32x8matrix.h"
+
+Adafruit_32x8matrix::Adafruit_32x8matrix(I2C *i2c, uint8_t i2c_addr, uint8_t i2c_addr2, uint8_t rotation, uint8_t rotation2, uint8_t brightness)
+
+ : _i2c(*i2c), _matrix(&_i2c), _matrix2(&_i2c), _i2c_addr(i2c_addr), _i2c_addr2(i2c_addr2), _rotation(rotation), _rotation2(rotation2), _brightness(brightness)
+
+{
+
+ _matrix2.begin(_i2c_addr2);
+ _matrix2.setBrightness(_brightness);
+ _matrix2.setRotation(_rotation2);
+ _matrix2.clear();
+ _matrix2.writeDisplay();
+
+ _matrix.begin(_i2c_addr);
+ _matrix.setBrightness(_brightness);
+ _matrix.setRotation(_rotation);
+ _matrix.clear();
+ _matrix.writeDisplay();
+
+
+}
+
+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
+ 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(1000/speed);
+ _matrix.clear();
+ _matrix2.clear();
+ }
+}
+
+
+void Adafruit_32x8matrix::showText(char * buffer, uint8_t buf_len, uint8_t speed)
+{
+ 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/speed);
+ _matrix.clear();
+ _matrix2.clear();
+
+}
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Adafruit_32x8matrix.h Wed Jun 28 19:27:51 2017 +0000
@@ -0,0 +1,32 @@
+#ifndef _ADAFRUIT_32X8MATRIX_H_
+#define _ADAFRUIT_32X8MATRIX_H_
+
+#include "Adafruit_LEDBackpack.h"
+#include "Adafruit_GFX.h"
+
+//notes
+//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
+
+
+class Adafruit_32x8matrix {
+public:
+ Adafruit_32x8matrix(I2C *i2c, uint8_t i2c_addr, uint8_t i2c_addr2, uint8_t rotation, uint8_t rotation2, uint8_t brightness);
+
+ void scrollText(char * , uint8_t , uint8_t );
+ void showText(char * , uint8_t , uint8_t );
+
+private:
+ I2C _i2c;
+ Adafruit_16x8matrix _matrix;
+ Adafruit_16x8matrix _matrix2;
+ uint8_t _i2c_addr;
+ uint8_t _i2c_addr2;
+ uint8_t _rotation;
+ uint8_t _rotation2;
+ uint8_t _brightness;
+
+};
+
+#endif
\ No newline at end of file
--- a/main.cpp Sat Apr 08 02:57:54 2017 +0000
+++ b/main.cpp Wed Jun 28 19:27:51 2017 +0000
@@ -1,49 +1,32 @@
#include "mbed.h"
-#include "Adafruit_LEDBackpack.h"
-#include "Adafruit_GFX.h"
+#include "Adafruit_32x8matrix.h"
+
+#define I2C_ADDR1 0x70
+#define I2C_ADDR2 0x71
+#define ROTATION1 0
+#define ROTATION2 2
+#define BRIGHTNESS 1
+
+Serial pc (USBTX,USBRX);
+
+void myidlethread(void);
+
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 myidlethread(void);
+Adafruit_32x8matrix matrix(&i2c, I2C_ADDR1, I2C_ADDR2, ROTATION1, ROTATION2, BRIGHTNESS);
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, "IoT Lab\0");
+ char buffer [50];
+ sprintf (buffer, "Welcome\0");
+ Thread::attach_idle_hook(myidlethread);
+
while(1)
{
- scrollText(buffer,strlen(buffer), 1000);
-
- Thread::attach_idle_hook (myidlethread);
-
+ matrix.scrollText(buffer,strlen(buffer), 80);
+
Thread::wait(10000);
}
@@ -56,29 +39,3 @@
}
-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);
- matrix2.writeDisplay();
- }else
- {
- matrix.drawChar(xoff + j*6, 0, buffer[j], 1, 0, 1);
- matrix.writeDisplay();
- matrix2.drawChar(xoff + j*6 - 16, 0, buffer[j], 1, 0, 1);
- matrix2.writeDisplay();
- }
- }
- xoff--; /* decrement x offset*/
- Thread::wait(1000/speed);
- matrix.clear();
- matrix2.clear();
- }
-}