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
Diff: main.cpp
- Revision:
- 11:996c98ad9d73
- Parent:
- 10:ee58d712c7fb
- Child:
- 19:2b14139fb19f
--- a/main.cpp Sun Nov 02 18:15:48 2014 +0000 +++ b/main.cpp Sun Nov 02 18:26:37 2014 +0000 @@ -8,45 +8,21 @@ DigitalOut led(LED1); Serial pc(USBTX, USBRX); Serial bluetooth(p28,p27); -static char line[99], line_buffer[99]; -static bool mode_buffer = 0; -static uint8_t interrupt_flag = 0; -int realTime; +char line[99]; void receive(); int main() { - static bool m_mode; - char buffer[4]; - bool dot; pc.baud(115200); bluetooth.baud(38400); - void (*foo)() = &receive; - bluetooth.attach(foo, Serial::RxIrq); - generator.generate("ABCD"); + bluetooth.attach(&receive, Serial::RxIrq); + generator.generate("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); while(true){ - /*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){ + if (strlen(line) > 0){ led = 0; generator.generate(line); memset(line, 0, sizeof(line)); } - 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(); + display.show(); } } @@ -55,22 +31,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{ - 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; + while(bluetooth.readable() && (j < i) && (j < 99)); } \ No newline at end of file