Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Hexi_KW40Z Hexi_OLED_SSD1351
main.cpp
00001 //Filarius Peter Usop 00002 //Mini Project 1 00003 //Uses LEDs, Buttons, Haptic, and OLEd 00004 00005 #include "mbed.h" 00006 #include "Hexi_OLED_SSD1351.h" 00007 #include "Hexi_KW40Z.h" 00008 #include "Functions.h" 00009 #include "string.h" 00010 00011 //SSD1351 Driver (OLED) Instantiation 00012 SSD1351 oled(PTB22, PTB21, PTC13, PTB20, PTE6, PTD15); 00013 00014 Timer t; 00015 00016 int main (void) 00017 { 00018 //Initialize buttons 00019 Button_Init(); 00020 00021 //Initialize the text properties to default 00022 oled_text_properties_t textProp = {0}; 00023 oled.GetTextProperties(&textProp); 00024 00025 //String Pointer 00026 char text[20]; 00027 00028 //Flag 00029 int flag = 1; 00030 00031 //Clear screen 00032 oled.DrawBox(0,0,96,96,COLOR_BLACK); 00033 00034 //Top Title 00035 strcpy((char *) text, "Stopwatch"); 00036 textProp.fontColor = COLOR_WHITE; 00037 textProp.alignParam = OLED_TEXT_ALIGN_CENTER; 00038 oled.SetTextProperties(&textProp); 00039 oled.TextBox((const uint8_t *) text,0,0,96,15); 00040 00041 textProp.fontColor = COLOR_RED; 00042 oled.SetTextProperties(&textProp); 00043 00044 t.start(); //Start stopwatch. You may remove this line 00045 00046 //Print to OLED 00047 sprintf(text, "%.0f", t.read()); 00048 oled.TextBox((uint8_t *) text,0,40,96,15); 00049 00050 while (1) { 00051 Thread::wait(1000); //Refresh every 1 second 00052 if (flag == 1) //Down button: Stops and resets the stopwatch 00053 { 00054 t.stop(); 00055 t.reset(); 00056 sprintf(text, "%.0f", t.read()); 00057 flag++; 00058 } 00059 else if (flag == 2) //Right button: Starts the stopwatch 00060 { 00061 if (but == 1) 00062 { 00063 t.start(); 00064 flag++; 00065 } 00066 else if (but == 0) flag--; 00067 } 00068 else if (flag == 3) //Left button: Stops the stopwatch 00069 { 00070 if (but == 2) 00071 { 00072 t.stop(); 00073 flag--; 00074 } 00075 else if (but == 0) flag = flag-2; 00076 } 00077 00078 //Update value on OLED 00079 sprintf(text, "%.0f", t.read()); 00080 oled.TextBox((uint8_t *) text,0,40,96,15); 00081 } 00082 }
Generated on Fri Jul 15 2022 09:25:20 by
1.7.2