hexiwear RTC display Serial
Dependencies: Hexi_KW40Z Hexi_OLED_SSD1351 mbed
main.cpp
00001 /* 00002 CREATED BY JAICHANGPARK AKA DREAMWALKER 00003 DATE : 2017. 06. 28 00004 00005 */ 00006 00007 #include "mbed.h" 00008 #include "Hexi_OLED_SSD1351.h" 00009 #include "Hexi_KW40Z.h" 00010 #include "string.h" 00011 #include "MTCH6102.h" 00012 00013 00014 DigitalOut led1(LED1); 00015 00016 /** 00017 * HEXIWEAR SERIAL PORT 00018 TX : PTD3, USBTX(WITH PC) 00019 RX : PTD2, USBRX(WITH PC) 00020 **/ 00021 00022 Serial serial(USBTX,USBRX,9600); //(TX, RX) 00023 00024 /* 00025 HEXIWEAR OLED INTERNAL DISPLAY PIN 00026 MOSI(SDI) : PTB22 00027 SCLK(SCK) : PTB21 00028 POWER : PTC13 ( INTERNAL POWER PORT) 00029 CS : PTB20 00030 RST : PTE6 00031 DC : PTD15 00032 */ 00033 SSD1351 display(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); 00034 00035 /* 00036 KW40Z INIT 00037 UART4 00038 TX : PTE24 00039 RX : PTE25 00040 */ 00041 00042 KW40Z kw40z_device(PTE24, PTE25); 00043 00044 // main() runs in its own thread in the OS 00045 int main() { 00046 00047 char time_text[20]; 00048 char date_text[25]; 00049 00050 // Use default properties 00051 oled_text_properties_t textProperties = {0}; 00052 display.GetTextProperties(&textProperties); 00053 display.FillScreen(COLOR_BLACK); 00054 00055 textProperties.fontColor = COLOR_WHITE; 00056 textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; 00057 display.SetTextProperties(&textProperties); 00058 00059 while (true) { 00060 00061 time_t seconds = time(NULL); 00062 const tm *t = localtime(&seconds); // Convert the unix time to actual time 00063 char* s = "AM"; // The suffix to use for the time of day 00064 int h = (t->tm_hour) + 18; // The hours 00065 int year = (t->tm_year) + 1947; 00066 if (h > 12){ // If it's entering 24/h time, change it to 12/h and add PM 00067 s = "PM"; 00068 h = h - 12; 00069 } 00070 00071 // Format the time 00072 sprintf(time_text,"%d:%d:%d %s",h, t->tm_min, t->tm_sec, s); 00073 sprintf(date_text,"%d-%d-%d",year, (t->tm_mon)+6, (t->tm_mday)+27); 00074 00075 serial.printf(time_text); 00076 serial.printf("\n"); 00077 serial.printf(date_text); 00078 serial.printf("\n"); 00079 00080 // Display the time on screen 00081 // oled_status_t SSD1351::TextBox(const uint8_t* text, int8_t xCrd, int8_t yCrd,uint8_t width,uint8_t height) 00082 display.TextBox((uint8_t *)time_text,2,2, 91, 15); 00083 display.TextBox((uint8_t *)date_text,2,16, 91, 15); 00084 led1 = !led1; 00085 wait(0.5); 00086 } 00087 } 00088 00089 void edited_time(){ 00090 00091 char buffer[32]; 00092 time_t init_time = time(NULL); 00093 strftime(buffer, 32, "%I:%M %p\n", localtime(&init_time)); 00094 printf("Time as a custom formatted string = %s", buffer); 00095 00096 } 00097
Generated on Thu Jul 14 2022 07:15:11 by
1.7.2