Hexiwear Program for my Hackster Hexiwear contest entry
Dependencies: Hexi_OLED_SSD1351
main.cpp
00001 #include "mbed.h" 00002 #include "Hexi_OLED_SSD1351.h" 00003 #include "string.h" 00004 00005 #include "images.h" 00006 00007 DigitalOut led_green(LED_GREEN); 00008 DigitalOut vib(PTB9); 00009 00010 Serial eddy(PTD3, PTD2); // tx rx 00011 00012 // Connect to the oled 00013 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); /* (MOSI,SCLK,POWER,CS,RST,DC) */ 00014 00015 bool armed = false; 00016 bool alarm = false; 00017 00018 int main() { 00019 00020 // Buffer to store label text 00021 char text[20]; 00022 00023 // Use default properties 00024 oled_text_properties_t textProperties = {0}; 00025 oled.GetTextProperties(&textProperties); 00026 00027 // Fill the screen 00028 oled.FillScreen(COLOR_BLACK); 00029 00030 const uint8_t *borderImage; 00031 borderImage = border_bmp; 00032 oled.DrawImage(borderImage,0,20); 00033 00034 // Set text color to white and left aligned 00035 textProperties.fontColor = COLOR_WHITE; 00036 textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; 00037 oled.SetTextProperties(&textProperties); 00038 00039 const uint8_t *armedImage; 00040 armedImage = lock_bmp; 00041 00042 const uint8_t *disarmedImage; 00043 disarmedImage = unlock_bmp; 00044 00045 const uint8_t *alarmImage; 00046 alarmImage = alarm_bmp; 00047 00048 while (true) { 00049 time_t seconds = time(NULL); // Get the time in unix format 00050 00051 const tm *t = localtime (&seconds); // Convert the unix time to actual time 00052 char* s = "AM"; // The suffix to use for the time of day 00053 int h = t->tm_hour; // The hours 00054 if (h > 12){ // If it's entering 24/h time, change it to 12/h and add PM 00055 s = "PM"; 00056 h = h - 12; 00057 } 00058 // Format the time 00059 sprintf(text,"%d:%d %s",h, t->tm_min, s); 00060 // Display the time on screen 00061 oled.TextBox((uint8_t *)text,2,2, 91, 15); 00062 00063 if(alarm){ 00064 vib = !vib; 00065 oled.DrawImage(alarmImage,0,20); 00066 }else{ 00067 if(armed){ 00068 oled.DrawImage(armedImage,0,20); 00069 }else{ 00070 oled.DrawImage(disarmedImage,0,20); 00071 } 00072 } 00073 00074 // Flash the green led 00075 led_green = !led_green; 00076 00077 if(eddy.readable()) { 00078 char read = eddy.getc(); 00079 00080 if(read == '0'){ 00081 armed = false; 00082 alarm = false; 00083 }else if (read == '1'){ 00084 armed = true; 00085 alarm = false; 00086 }else if (read == '2'){ 00087 alarm = true; 00088 } 00089 } 00090 00091 Thread::wait(1000); 00092 } 00093 } 00094 00095
Generated on Wed Jul 20 2022 19:37:28 by 1.7.2