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

Committer:
DaniusKalv
Date:
Sun Nov 02 18:15:48 2014 +0000
Revision:
10:ee58d712c7fb
Parent:
9:ed7e8a6fc537
Child:
11:996c98ad9d73
Child:
12:a8364a98c38c
Fucking interrupt messes up variables, better use thread

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DaniusKalv 0:06ac39308380 1 #include "mbed.h"
DaniusKalv 0:06ac39308380 2 #include "matrix.h"
DaniusKalv 2:3cc1e2dec7a2 3 #include "text.h"
DaniusKalv 6:76b89d8b62a0 4 #include <string>
DaniusKalv 2:3cc1e2dec7a2 5
DaniusKalv 2:3cc1e2dec7a2 6 text generator;
DaniusKalv 3:35a47548d29d 7 matrix display(p13, p12, p11, p14, p15, p17, p16);
DaniusKalv 6:76b89d8b62a0 8 DigitalOut led(LED1);
DaniusKalv 5:76dd6da3e640 9 Serial pc(USBTX, USBRX);
DaniusKalv 5:76dd6da3e640 10 Serial bluetooth(p28,p27);
DaniusKalv 10:ee58d712c7fb 11 static char line[99], line_buffer[99];
DaniusKalv 10:ee58d712c7fb 12 static bool mode_buffer = 0;
DaniusKalv 10:ee58d712c7fb 13 static uint8_t interrupt_flag = 0;
DaniusKalv 10:ee58d712c7fb 14 int realTime;
DaniusKalv 6:76b89d8b62a0 15 void receive();
DaniusKalv 0:06ac39308380 16
DaniusKalv 0:06ac39308380 17 int main() {
DaniusKalv 10:ee58d712c7fb 18 static bool m_mode;
DaniusKalv 10:ee58d712c7fb 19 char buffer[4];
DaniusKalv 10:ee58d712c7fb 20 bool dot;
DaniusKalv 6:76b89d8b62a0 21 pc.baud(115200);
DaniusKalv 5:76dd6da3e640 22 bluetooth.baud(38400);
DaniusKalv 10:ee58d712c7fb 23 void (*foo)() = &receive;
DaniusKalv 10:ee58d712c7fb 24 bluetooth.attach(foo, Serial::RxIrq);
DaniusKalv 10:ee58d712c7fb 25 generator.generate("ABCD");
DaniusKalv 5:76dd6da3e640 26 while(true){
DaniusKalv 10:ee58d712c7fb 27 /*if (interrupt_flag == 1){
DaniusKalv 10:ee58d712c7fb 28 m_mode = mode_buffer;
DaniusKalv 10:ee58d712c7fb 29 memcpy(line, line_buffer, sizeof(line_buffer));
DaniusKalv 10:ee58d712c7fb 30 interrupt_flag = 0;
DaniusKalv 10:ee58d712c7fb 31 }*/
DaniusKalv 10:ee58d712c7fb 32 pc.printf("\r\nMode = %i", m_mode);
DaniusKalv 10:ee58d712c7fb 33 if (strlen(line) > 0 && m_mode == 0){
DaniusKalv 6:76b89d8b62a0 34 led = 0;
DaniusKalv 5:76dd6da3e640 35 generator.generate(line);
DaniusKalv 6:76b89d8b62a0 36 memset(line, 0, sizeof(line));
DaniusKalv 5:76dd6da3e640 37 }
DaniusKalv 10:ee58d712c7fb 38 else if (strlen(line) > 0 && m_mode == 1){
DaniusKalv 10:ee58d712c7fb 39 led = 0;
DaniusKalv 10:ee58d712c7fb 40 memset(line, 0, sizeof(line));
DaniusKalv 10:ee58d712c7fb 41 }
DaniusKalv 10:ee58d712c7fb 42 if(m_mode == 1){
DaniusKalv 10:ee58d712c7fb 43 time_t seconds = time(NULL);
DaniusKalv 10:ee58d712c7fb 44 strftime(buffer, 4, "%H%M", localtime(&seconds));
DaniusKalv 10:ee58d712c7fb 45 if ((seconds % 2) == 0) dot = true;
DaniusKalv 10:ee58d712c7fb 46 else dot = false;
DaniusKalv 10:ee58d712c7fb 47 display.clock(buffer, dot);
DaniusKalv 10:ee58d712c7fb 48 }
DaniusKalv 10:ee58d712c7fb 49 else display.show();
DaniusKalv 5:76dd6da3e640 50 }
DaniusKalv 6:76b89d8b62a0 51 }
DaniusKalv 6:76b89d8b62a0 52
DaniusKalv 6:76b89d8b62a0 53 void receive(){
DaniusKalv 6:76b89d8b62a0 54 led = 1;
DaniusKalv 6:76b89d8b62a0 55 int i, j = 0;
DaniusKalv 6:76b89d8b62a0 56 i = 10 * (bluetooth.getc() - 48);
DaniusKalv 6:76b89d8b62a0 57 i += bluetooth.getc() - 48;
DaniusKalv 10:ee58d712c7fb 58 if(i > 0){
DaniusKalv 10:ee58d712c7fb 59 mode_buffer = false;
DaniusKalv 10:ee58d712c7fb 60 do{
DaniusKalv 10:ee58d712c7fb 61 line_buffer[j] = bluetooth.getc();
DaniusKalv 10:ee58d712c7fb 62 j++;
DaniusKalv 10:ee58d712c7fb 63 wait(0.0004);
DaniusKalv 10:ee58d712c7fb 64 }
DaniusKalv 10:ee58d712c7fb 65 while(bluetooth.readable() && (j < i) && (j < 99));
DaniusKalv 6:76b89d8b62a0 66 }
DaniusKalv 10:ee58d712c7fb 67 else{
DaniusKalv 10:ee58d712c7fb 68 pc.printf("\r\nClock mode");
DaniusKalv 10:ee58d712c7fb 69 mode_buffer = true;
DaniusKalv 10:ee58d712c7fb 70 bluetooth.gets(line, 10);
DaniusKalv 10:ee58d712c7fb 71 realTime = atoi(line_buffer);
DaniusKalv 10:ee58d712c7fb 72 set_time(realTime);
DaniusKalv 10:ee58d712c7fb 73 pc.printf("\r\nTime : %i Mode : %i", realTime, mode_buffer);
DaniusKalv 10:ee58d712c7fb 74 }
DaniusKalv 10:ee58d712c7fb 75 interrupt_flag = 1;
DaniusKalv 0:06ac39308380 76 }