Blue LED matrix (8x16) program. Gets text string through bluetooth and displays it on led matrix. Also has a clock function- get system time from a phone through bluetooth and enters clock mode. In clock mode it acts as a clock showing hours and minutes and blinking led every second. Clock mode can be broken if a text string is received through bluetooth.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
DaniusKalv
Date:
Wed Nov 19 09:19:28 2014 +0000
Parent:
18:fe3809cdc50a
Parent:
11:996c98ad9d73
Child:
20:8055a5b5dba0
Commit message:
merged branches

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp.orig Show annotated file Show diff for this revision Revisions of this file
matrix.cpp Show annotated file Show diff for this revision Revisions of this file
matrix.cpp.orig Show annotated file Show diff for this revision Revisions of this file
matrix.h Show annotated file Show diff for this revision Revisions of this file
matrix.h.orig Show annotated file Show diff for this revision Revisions of this file
--- a/letters.h	Wed Nov 19 09:14:55 2014 +0000
+++ b/letters.h	Wed Nov 19 09:19:28 2014 +0000
@@ -398,15 +398,15 @@
     1 1 0 0 0 0 0 0 0xC0
 };*/
 
-uint8_t letterk[8] = { 0x00, 0x00, 0x90, 0xA0, 0xC0, 0xA0, 0x90, 0x00};
+uint8_t letterk[8] = { 0x00, 0x00, 0x00, 0x90, 0xA0, 0xC0, 0xA0, 0x90};
   /*0 0 0 0 0 0 0 0 0x00
     0 0 0 0 0 0 0 0 0x00
+    0 0 0 0 0 0 0 0 0x00
     1 0 0 1 0 0 0 0 0x90
     1 0 1 0 0 0 0 0 0xA0
     1 1 0 0 0 0 0 0 0xC0
     1 0 1 0 0 0 0 0 0xA0
     1 0 0 1 0 0 0 0 0x90
-    0 0 0 0 0 0 0 0 0x00
 };*/
 
 uint8_t letterl[8] = { 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80};
@@ -420,37 +420,37 @@
     1 0 0 0 0 0 0 0 0x80
 };*/
 
-uint8_t letterm[8] = { 0x00, 0x00, 0xF0, 0xA8, 0xA8, 0xA8, 0xA8, 0x00};
+uint8_t letterm[8] = { 0x00, 0x00, 0x00, 0xF0, 0xA8, 0xA8, 0xA8, 0xA8};
   /*0 0 0 0 0 0 0 0 0x00
     0 0 0 0 0 0 0 0 0x00
+    0 0 0 0 0 0 0 0 0x00
     1 1 1 1 0 0 0 0 0xF0
     1 0 1 0 1 0 0 0 0xA8
     1 0 1 0 1 0 0 0 0xA8
     1 0 1 0 1 0 0 0 0xA8
     1 0 1 0 1 0 0 0 0xA8
-    0 0 0 0 0 0 0 0 0x00
 };*/
 
-uint8_t lettern[8] = { 0x00, 0x00, 0xE0, 0x90, 0x90, 0x90, 0x90, 0x00};
+uint8_t lettern[8] = { 0x00, 0x00, 0x00, 0xE0, 0x90, 0x90, 0x90, 0x90};
   /*0 0 0 0 0 0 0 0 0x00
     0 0 0 0 0 0 0 0 0x00
+    0 0 0 0 0 0 0 0 0x00
     1 1 1 0 0 0 0 0 0xE0
     1 0 0 1 0 0 0 0 0x90
     1 0 0 1 0 0 0 0 0x90
     1 0 0 1 0 0 0 0 0x90
     1 0 0 1 0 0 0 0 0x90
-    0 0 0 0 0 0 0 0 0x00
 };*/
 
-uint8_t lettero[8] = { 0x00, 0x00, 0x60, 0x90, 0x90, 0x90, 0x60, 0x00};
+uint8_t lettero[8] = { 0x00, 0x00, 0x00, 0x60, 0x90, 0x90, 0x90, 0x60};
   /*0 0 0 0 0 0 0 0 0x00
     0 0 0 0 0 0 0 0 0x00
+    0 0 0 0 0 0 0 0 0x00
     0 1 1 0 0 0 0 0 0x60
     1 0 0 1 0 0 0 0 0x90
     1 0 0 1 0 0 0 0 0x90
     1 0 0 1 0 0 0 0 0x90
     0 1 1 0 0 0 0 0 0x60 
-    0 0 0 0 0 0 0 0 0x00
 };*/
 
 uint8_t letterp[8] = { 0x00, 0x00, 0xE0, 0x90, 0x90, 0xE0, 0x80, 0x80};
@@ -508,31 +508,32 @@
     0 1 1 1 0 0 0 0 0x70
 };*/
 
-uint8_t letteru[8] = { 0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x70, 0x00};
+uint8_t letteru[8] = { 0x00, 0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x70};
   /*0 0 0 0 0 0 0 0 0x00
     0 0 0 0 0 0 0 0 0x00
+    0 0 0 0 0 0 0 0 0x00
     1 0 0 1 0 0 0 0 0x90
     1 0 0 1 0 0 0 0 0x90
     1 0 0 1 0 0 0 0 0x90
     1 0 0 1 0 0 0 0 0x90
     0 1 1 1 0 0 0 0 0x70
-    0 0 0 0 0 0 0 0 0x00
 };*/
 
-uint8_t letterv[8] = { 0x00, 0x00, 0x88, 0x88, 0x88, 0x50, 0x20, 0x00};
+uint8_t letterv[8] = { 0x00, 0x00, 0x00, 0x88, 0x88, 0x88, 0x50, 0x20};
   /*0 0 0 0 0 0 0 0 0x00
     0 0 0 0 0 0 0 0 0x00
+    0 0 0 0 0 0 0 0 0x00
     1 0 0 0 1 0 0 0 0x88
     1 0 0 0 1 0 0 0 0x88
     1 0 0 0 1 0 0 0 0x88
     0 1 0 1 0 0 0 0 0x50
     0 0 1 0 0 0 0 0 0x20
-    0 0 0 0 0 0 0 0 0x00
 };*/
 
-uint8_t letterw[8] = { 0x00, 0x00, 0x88, 0x88, 0xA8, 0xA8, 0x70, 0x00};
+uint8_t letterw[8] = { 0x00, 0x00, 0x00, 0x88, 0x88, 0xA8, 0xA8, 0x70};
   /*0 0 0 0 0 0 0 0 0x00
     0 0 0 0 0 0 0 0 0x00
+    0 0 0 0 0 0 0 0 0x00
     1 0 0 0 1 0 0 0 0x88
     1 0 0 0 1 0 0 0 0x88
     1 0 1 0 1 0 0 0 0xA8
@@ -541,37 +542,37 @@
     0 0 0 0 0 0 0 0 0x00
 };*/
 
-uint8_t letterx[8] = { 0x00, 0x00, 0x90, 0x90, 0x60, 0x90, 0x90, 0x00};
+uint8_t letterx[8] = { 0x00, 0x00, 0x00, 0x90, 0x90, 0x60, 0x90, 0x90};
   /*0 0 0 0 0 0 0 0 0x00
     0 0 0 0 0 0 0 0 0x00
+    0 0 0 0 0 0 0 0 0x00
     1 0 0 1 0 0 0 0 0x90
     1 0 0 1 0 0 0 0 0x90
     0 1 1 0 0 0 0 0 0x60
     1 0 0 1 0 0 0 0 0x90
     1 0 0 1 0 0 0 0 0x90
-    0 0 0 0 0 0 0 0 0x00
 };*/
 
-uint8_t lettery[8] = { 0x00, 0x00, 0x90, 0x90, 0x70, 0x10, 0xE0, 0x00};
-  /*0 0 0 0 0 0 0 0 0x00
+uint8_t lettery[8] = { 0x00, 0x00, 0x00, 0x90, 0x90, 0x70, 0x10, 0xE0};
+  /*0 0 0 0 0 0 0 0 0x00    
+    0 0 0 0 0 0 0 0 0x00
     0 0 0 0 0 0 0 0 0x00
     1 0 0 1 0 0 0 0 0x90
     1 0 0 1 0 0 0 0 0x90
     0 1 1 1 0 0 0 0 0x70
     0 0 0 1 0 0 0 0 0x10
     1 1 1 0 0 0 0 0 0xE0
-    0 0 0 0 0 0 0 0 0x00
 };*/
 
-uint8_t letterz[8] = { 0x00, 0x00, 0xF0, 0x20, 0x40, 0x80, 0xF0, 0x00};
+uint8_t letterz[8] = { 0x00, 0x00, 0x00, 0xF0, 0x20, 0x40, 0x80, 0xF0};
   /*0 0 0 0 0 0 0 0 0x00
     0 0 0 0 0 0 0 0 0x00
+    0 0 0 0 0 0 0 0 0x00
     1 1 1 1 0 0 0 0 0xF0
     0 0 1 0 0 0 0 0 0x20
     0 1 0 0 0 0 0 0 0x40
     1 0 0 0 0 0 0 0 0x80
     1 1 1 1 0 0 0 0 0xF0
-    0 0 0 0 0 0 0 0 0x00
 };*/
 
 uint8_t letterGap[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
--- a/main.cpp	Wed Nov 19 09:14:55 2014 +0000
+++ b/main.cpp	Wed Nov 19 09:19:28 2014 +0000
@@ -50,7 +50,6 @@
             display.clock(buffer, dot);
         }
         else if (interrupt_flag == 0) display.show();
-        //wait(0.1);
     }
 }
 
@@ -59,14 +58,10 @@
     int i, j = 0;
     i = 10 * (bluetooth.getc() - 48);
     i += bluetooth.getc() - 48;
-    if(i > 0){
-        mode_buffer = false;
-        do{ 
-            line_buffer[j] = bluetooth.getc();
-            j++;
-            wait(0.0004);       
-        }
-        while(bluetooth.readable() && (j < i) && (j < 99));
+    do{ 
+        line[j] = bluetooth.getc();
+        j++;
+        wait(0.0004);       
     }
     else{
         mode_buffer = true;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp.orig	Wed Nov 19 09:19:28 2014 +0000
@@ -0,0 +1,84 @@
+#include "mbed.h"
+#include "matrix.h"
+#include "text.h"
+#include <string>
+
+text generator;
+matrix display(p13, p12, p11, p14, p15, p17, p16);
+DigitalOut led(LED1);
+Serial pc(USBTX, USBRX);
+Serial bluetooth(p28,p27);
+char line[99];
+char line_buffer[99];
+volatile bool mode_buffer = 0;
+volatile uint8_t interrupt_flag = 0;
+volatile int realTime;
+void receive();
+
+int main() {
+    bool m_mode = 0;
+    char buffer[4];
+    bool dot;
+    pc.baud(115200);
+    bluetooth.baud(38400);
+    void (*foo)() = &receive;
+    bluetooth.attach(foo, Serial::RxIrq);
+    generator.generate("Hello world!");
+    while(true){
+        if (interrupt_flag == 1){
+            pc.printf("\r\nIn interrupt flag!");
+            m_mode = mode_buffer;
+            memcpy(line, line_buffer, sizeof(line_buffer));
+            memset(line_buffer, 0, sizeof(line_buffer));
+            interrupt_flag = 0;
+        }
+        pc.printf("\r\nMode = %i", m_mode);
+        if (strlen(line) > 0 && m_mode == 0 && interrupt_flag == 0){  
+            led = 0;  
+            generator.generate(line);
+            memset(line, 0, sizeof(line));
+        }
+        else if (strlen(line) > 0 && m_mode == 1 && interrupt_flag == 0){
+            led = 0;
+            memset(line, 0, sizeof(line));
+        }
+        if(m_mode == 1 && interrupt_flag == 0){
+            time_t seconds = time(NULL);
+            strftime(buffer, 4, "%H%M", localtime(&seconds)); 
+            if ((seconds % 2) == 0) dot = true;
+            else dot = false; 
+            display.clock(buffer, dot);
+        }
+        else if (interrupt_flag == 0) display.show();
+        //wait(0.1);
+    }
+}
+
+void receive(){
+    led = 1;
+    int i, j = 0;
+    i = 10 * (bluetooth.getc() - 48);
+    i += bluetooth.getc() - 48;
+    if(i > 0){
+        mode_buffer = false;
+        do{ 
+            line_buffer[j] = bluetooth.getc();
+            j++;
+            wait(0.0004);       
+        }
+        while(bluetooth.readable() && (j < i) && (j < 99));
+    }
+    else{
+        mode_buffer = true;
+        for (int i = 0; i < 10; i++){                   
+            line_buffer[i] = bluetooth.getc();
+            wait(0.0004);
+        }
+        realTime = atoi(line_buffer);
+        set_time(realTime);
+    }  
+    while (bluetooth.readable()){
+            bluetooth.getc();
+    }
+    interrupt_flag = 1; 
+}
\ No newline at end of file
--- a/matrix.cpp	Wed Nov 19 09:14:55 2014 +0000
+++ b/matrix.cpp	Wed Nov 19 09:19:28 2014 +0000
@@ -19,7 +19,6 @@
     for (int i = 15; i < length; i++){
         for (int j = 0; j < 8; j++){
             multiplex();
-            clear();
         }
         for (int g = 0; g < 15; g++){
             for (int h = 0; h < 8; h++){
@@ -132,4 +131,4 @@
         pc.printf("\r\n");
     }
     pc.printf("\r\n");
-} 
\ No newline at end of file
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matrix.cpp.orig	Wed Nov 19 09:19:28 2014 +0000
@@ -0,0 +1,135 @@
+#include "matrix.h"
+#include "numbers.h"
+
+matrix::matrix(PinName _in1, PinName _in2, PinName _in3, PinName _clr, 
+PinName _clr1, PinName _clk, PinName _clk1): local("local"), in1(_in1), in2(_in2), 
+in3(_in3), clr(_clr), clr1(_clr1), clk(_clk), clk1(_clk1), pc(USBTX, USBRX){
+};
+
+void matrix::show(){
+    char temp[8];
+    fp = fopen("/local/out.txt", "r");
+    fscanf(fp, "%i", &length);
+    for (int i = 0; i < 16; i++){
+        fscanf(fp, "%s", temp);
+        for (int j = 0; j < 8; j++){
+            display[7 - j][i] = temp[j] - 48;    
+        }
+    }
+    for (int i = 15; i < length; i++){
+        for (int j = 0; j < 8; j++){
+            multiplex();
+            clear();
+        }
+        for (int g = 0; g < 15; g++){
+            for (int h = 0; h < 8; h++){
+                display[h][g] = display[h][g + 1];
+            }
+        }
+        fscanf(fp, "%s", temp);
+        for (int j = 0; j < 8; j++){
+            display[j][15] = temp[7 - j] - 48;
+        }
+    }    
+    fclose(fp);
+}
+
+void matrix::clear(){
+    in1 = 1;
+    in2 = 0;
+    in3 = 0;
+    clk = 0;
+    clk1 = 0;
+    clr = 0;
+    clr1 = 0;
+    clr = 1;
+    clr1 = 1;
+}
+
+void matrix::multiplex(){
+    int a[8] = {0, 1, 1, 1, 1, 1, 1, 1};
+    clear();
+    for (int i = 0; i < 8; i++){
+        clear();
+        for (int g = 0; g < 8; g++){
+            in1 = a[g];
+            //pc.printf("%i", a[g]);
+            clk = 1;
+            //wait(del);
+            clk = 0;
+            //wait(del);    
+        }
+        //pc.printf("\r\n");
+        for (int j = 7; j > (-1); j--){
+            in3 = display[i][j];
+            in2 = display[i][j + 8];
+            //pc.printf("%i", show[i][j]);
+            clk1 = 1;
+            //wait(del);
+            clk1 = 0;
+            //wait(del);      
+        }
+        wait(0.001);
+        //pc.printf("\r\n");
+        a[i] = 1;
+        a[i + 1] = 0;
+    }    
+}
+
+void matrix::clock(char *buffer, bool dot){
+    //pc.printf("\r\nClock %s", buffer);
+    
+    memset(display, 0, sizeof(display));
+    
+    int digit = int(buffer[0]) - 48;
+    //pc.printf("\r\nDigit= %i", digit);
+    
+    for (int i = 0; i < 3; i++){
+        for (int j = 0; j < 8; j++){
+            display[j][i] = ((number[i][digit] & (1 << (7 - j))) >> (7 - j));
+        };       
+    };  
+    
+    digit = int(buffer[1]) - 48;
+    //pc.printf("\r\nDigit= %i", digit);
+    
+    for (int i = 4; i < 7; i++){
+        for (int j = 0; j < 8; j++){
+            display[j][i] = ((number[i - 4][digit] & (1 << (7 - j))) >> (7 - j));
+        };       
+    }; 
+    
+    digit = int(buffer[2]) - 48;
+    //pc.printf("\r\nDigit= %i", digit);
+    
+    for (int i = 9; i < 12; i++){
+        for (int j = 0; j < 8; j++){
+            display[j][i] = ((number[i - 9][digit] & (1 << (7 - j))) >> (7 - j));
+        };       
+    }; 
+    
+    digit = int(buffer[3]) - 48;
+    //pc.printf("\r\nDigit= %i", digit);
+    
+    for (int i = 13; i < 16; i++){
+        for (int j = 0; j < 8; j++){
+            display[j][i] = ((number[i - 13][digit] & (1 << (7 - j))) >> (7 - j));
+        };       
+    }; 
+    
+    if (dot) display[6][7] = 1;
+    //see();
+    for (int i = 0; i < 10; i++) multiplex();
+    //while (!pc.getc());
+};
+
+void matrix::see(){
+    pc.printf("\r\n");
+    for (int i = 0; i < 8; i++){
+        for (int j = 0; j < 16 ; j++){
+            pc.printf("%i ", display[i][j]);
+        }
+        pc.printf("\r\n");
+    }
+    pc.printf("\r\n");
+} 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matrix.h.orig	Wed Nov 19 09:19:28 2014 +0000
@@ -0,0 +1,31 @@
+#ifndef MBED_MATRIX_H_
+#define MBED_MATRIX_H_
+
+#include "mbed.h"
+
+void led_thread(void const *args);
+
+class matrix{
+private:
+    int length;
+    int display[8][16];
+    Serial pc;
+    LocalFileSystem local;
+    FILE *fp; 
+    DigitalOut in3;
+    DigitalOut in2;
+    DigitalOut in1;
+    DigitalOut clr1;
+    DigitalOut clr;
+    DigitalOut clk1;
+    DigitalOut clk;   
+public:
+    matrix(PinName _in1, PinName _in2, PinName _in3, PinName _clr, PinName _clr1, PinName _clk, PinName _clk1);
+    void show();
+    void clear();
+    void multiplex();
+    void clock(char *buffer, bool dot);
+    void see();
+};    
+
+#endif /* matrix_H_ */
\ No newline at end of file