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
main.cpp
- Committer:
- DaniusKalv
- Date:
- 2014-11-02
- Revision:
- 10:ee58d712c7fb
- Parent:
- 9:ed7e8a6fc537
- Child:
- 11:996c98ad9d73
- Child:
- 12:a8364a98c38c
File content as of revision 10:ee58d712c7fb:
#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); 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); void (*foo)() = &receive; bluetooth.attach(foo, Serial::RxIrq); generator.generate("ABCD"); 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){ 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(); } } 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{ 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; }