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

Revision:
10:ee58d712c7fb
Parent:
9:ed7e8a6fc537
Child:
11:996c98ad9d73
Child:
12:a8364a98c38c
--- a/main.cpp	Sun Nov 02 11:25:00 2014 +0000
+++ b/main.cpp	Sun Nov 02 18:15:48 2014 +0000
@@ -8,21 +8,45 @@
 DigitalOut led(LED1);
 Serial pc(USBTX, USBRX);
 Serial bluetooth(p28,p27);
-char line[99];
+static char line[99], line_buffer[99];
+static bool mode_buffer = 0;
+static uint8_t interrupt_flag = 0;
+int realTime;
 void receive();
 
 int main() {
+    static bool m_mode;
+    char buffer[4];
+    bool dot;
     pc.baud(115200);
     bluetooth.baud(38400);
-    bluetooth.attach(&receive, Serial::RxIrq);
-    generator.generate("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
+    void (*foo)() = &receive;
+    bluetooth.attach(foo, Serial::RxIrq);
+    generator.generate("ABCD");
     while(true){
-        if (strlen(line) > 0){  
+        /*if (interrupt_flag == 1){
+            m_mode = mode_buffer;
+            memcpy(line, line_buffer, sizeof(line_buffer));
+            interrupt_flag = 0;
+        }*/
+        pc.printf("\r\nMode = %i", m_mode);
+        if (strlen(line) > 0 && m_mode == 0){  
             led = 0;  
             generator.generate(line);
             memset(line, 0, sizeof(line));
         }
-        display.show();
+        else if (strlen(line) > 0 && m_mode == 1){
+            led = 0;
+            memset(line, 0, sizeof(line));
+        }
+        if(m_mode == 1){
+            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 display.show();
     }
 }
 
@@ -31,10 +55,22 @@
     int i, j = 0;
     i = 10 * (bluetooth.getc() - 48);
     i += bluetooth.getc() - 48;
-    do{ 
-        line[j] = bluetooth.getc();
-        j++;
-        wait(0.0004);       
+    if(i > 0){
+        mode_buffer = false;
+        do{ 
+            line_buffer[j] = bluetooth.getc();
+            j++;
+            wait(0.0004);       
+        }
+        while(bluetooth.readable() && (j < i) && (j < 99));
     }
-    while(bluetooth.readable() && (j < i) && (j < 99));
+    else{
+        pc.printf("\r\nClock mode");
+        mode_buffer = true;
+        bluetooth.gets(line, 10);
+        realTime = atoi(line_buffer);
+        set_time(realTime);
+        pc.printf("\r\nTime : %i Mode : %i", realTime, mode_buffer);
+    }  
+    interrupt_flag = 1; 
 }
\ No newline at end of file