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:
Tue Nov 18 19:38:30 2014 +0000
Revision:
15:ba91aa788443
Parent:
14:adbb11e53c70
Child:
17:9889611a4ad1
Fixed interrupt and it's working!

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 15:ba91aa788443 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 15:ba91aa788443 11 char line[99];
DaniusKalv 15:ba91aa788443 12 char line_buffer[99];
DaniusKalv 15:ba91aa788443 13 volatile bool mode_buffer = 0;
DaniusKalv 15:ba91aa788443 14 volatile uint8_t interrupt_flag = 0;
DaniusKalv 15:ba91aa788443 15 volatile int realTime;
DaniusKalv 15:ba91aa788443 16 void receive();
DaniusKalv 0:06ac39308380 17
DaniusKalv 15:ba91aa788443 18 int main() {
DaniusKalv 15:ba91aa788443 19 bool m_mode = 0;
DaniusKalv 10:ee58d712c7fb 20 char buffer[4];
DaniusKalv 10:ee58d712c7fb 21 bool dot;
DaniusKalv 6:76b89d8b62a0 22 pc.baud(115200);
DaniusKalv 15:ba91aa788443 23 bluetooth.baud(38400);
DaniusKalv 15:ba91aa788443 24 void (*foo)() = &receive;
DaniusKalv 15:ba91aa788443 25 bluetooth.attach(foo, Serial::RxIrq);
DaniusKalv 10:ee58d712c7fb 26 generator.generate("ABCD");
DaniusKalv 15:ba91aa788443 27 while(true){
DaniusKalv 15:ba91aa788443 28 if (interrupt_flag == 1){
DaniusKalv 15:ba91aa788443 29 pc.printf("\r\nIn interrupt flag!");
DaniusKalv 15:ba91aa788443 30 m_mode = mode_buffer;
DaniusKalv 10:ee58d712c7fb 31 memcpy(line, line_buffer, sizeof(line_buffer));
DaniusKalv 15:ba91aa788443 32 memset(line_buffer, 0, sizeof(line_buffer));
DaniusKalv 15:ba91aa788443 33 interrupt_flag = 0;
DaniusKalv 15:ba91aa788443 34 }
DaniusKalv 15:ba91aa788443 35 pc.printf("\r\nMode = %i", m_mode);
DaniusKalv 15:ba91aa788443 36 if (strlen(line) > 0 && m_mode == 0 && interrupt_flag == 0){
DaniusKalv 15:ba91aa788443 37 led = 0;
DaniusKalv 15:ba91aa788443 38 generator.generate(line);
DaniusKalv 15:ba91aa788443 39 memset(line, 0, sizeof(line));
DaniusKalv 15:ba91aa788443 40 }
DaniusKalv 15:ba91aa788443 41 else if (strlen(line) > 0 && m_mode == 1 && interrupt_flag == 0){
DaniusKalv 13:96590015edd8 42 led = 0;
DaniusKalv 15:ba91aa788443 43 memset(line, 0, sizeof(line));
DaniusKalv 5:76dd6da3e640 44 }
DaniusKalv 15:ba91aa788443 45 if(m_mode == 1 && interrupt_flag == 0){
DaniusKalv 10:ee58d712c7fb 46 time_t seconds = time(NULL);
DaniusKalv 15:ba91aa788443 47 strftime(buffer, 4, "%H%M", localtime(&seconds));
DaniusKalv 10:ee58d712c7fb 48 if ((seconds % 2) == 0) dot = true;
DaniusKalv 15:ba91aa788443 49 else dot = false;
DaniusKalv 10:ee58d712c7fb 50 display.clock(buffer, dot);
DaniusKalv 10:ee58d712c7fb 51 }
DaniusKalv 15:ba91aa788443 52 else if (interrupt_flag == 0) display.show();
DaniusKalv 15:ba91aa788443 53 wait(0.1);
DaniusKalv 5:76dd6da3e640 54 }
DaniusKalv 6:76b89d8b62a0 55 }
DaniusKalv 6:76b89d8b62a0 56
DaniusKalv 15:ba91aa788443 57 void receive(){
DaniusKalv 15:ba91aa788443 58 led = 1;
DaniusKalv 15:ba91aa788443 59 int i, j = 0;
DaniusKalv 15:ba91aa788443 60 i = 10 * (bluetooth.getc() - 48);
DaniusKalv 15:ba91aa788443 61 i += bluetooth.getc() - 48;
DaniusKalv 15:ba91aa788443 62 if(i > 0){
DaniusKalv 15:ba91aa788443 63 mode_buffer = false;
DaniusKalv 15:ba91aa788443 64 do{
DaniusKalv 15:ba91aa788443 65 line_buffer[j] = bluetooth.getc();
DaniusKalv 15:ba91aa788443 66 j++;
DaniusKalv 15:ba91aa788443 67 wait(0.0004);
DaniusKalv 10:ee58d712c7fb 68 }
DaniusKalv 15:ba91aa788443 69 while(bluetooth.readable() && (j < i) && (j < 99));
DaniusKalv 6:76b89d8b62a0 70 }
DaniusKalv 15:ba91aa788443 71 else{
DaniusKalv 15:ba91aa788443 72 mode_buffer = true;
DaniusKalv 15:ba91aa788443 73 for (int i = 0; i < 10; i++){
DaniusKalv 15:ba91aa788443 74 line_buffer[i] = bluetooth.getc();
DaniusKalv 15:ba91aa788443 75 wait(0.0004);
DaniusKalv 15:ba91aa788443 76 }
DaniusKalv 15:ba91aa788443 77 realTime = atoi(line_buffer);
DaniusKalv 15:ba91aa788443 78 set_time(realTime);
DaniusKalv 15:ba91aa788443 79 }
DaniusKalv 15:ba91aa788443 80 while (bluetooth.readable()){
DaniusKalv 15:ba91aa788443 81 bluetooth.getc();
DaniusKalv 15:ba91aa788443 82 }
DaniusKalv 15:ba91aa788443 83 interrupt_flag = 1;
DaniusKalv 0:06ac39308380 84 }