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: BME280 BMP280 TextLCD
LCD_COMMAND.cpp
00001 #include "LCD_COMMAND.hpp" 00002 void LCD_Write_Year() 00003 { 00004 Time_Lock_Main.lock();//Appling lock for critial section 00005 if(Log_Value == 1){pc.printf("In LCD_Write_Year Time lock taken\n");} 00006 time_t Time = time(NULL); 00007 tm* Time_Pointer = localtime(&Time); 00008 int Years = 1900 + Time_Pointer->tm_year; 00009 Time_Lock_Main.unlock();//Releasing lock for critial section 00010 if(Log_Value == 1){pc.printf("In LCD_Write_Year Time lock released\n");} 00011 stringstream ss; 00012 ss << Years; 00013 string Year_String = ss.str(); 00014 LCD.DDRAM_Address(0x00); 00015 LCD.Write_String("Set Year"); 00016 LCD.DDRAM_Address(0x40); 00017 LCD.Write_String(Year_String); 00018 } 00019 void LCD_Write_Month() 00020 { 00021 Time_Lock_Main.lock();//Appling lock for critial section 00022 if(Log_Value == 1){pc.printf("In LCD_Write_Month Time lock taken\n");} 00023 time_t Time = time(NULL); 00024 tm* Time_Pointer = localtime(&Time); 00025 int Months = 1 + Time_Pointer->tm_mon; 00026 Time_Lock_Main.unlock();//Releasing lock for critial section 00027 if(Log_Value == 1){pc.printf("In LCD_Write_Month Time lock released\n");} 00028 stringstream ss; 00029 ss << Months; 00030 string Month_String = ss.str(); 00031 LCD.DDRAM_Address(0x00); 00032 LCD.Write_String("Set Month"); 00033 LCD.DDRAM_Address(0x40); 00034 LCD.Write_String(Month_String); 00035 } 00036 void LCD_Write_Day() 00037 { 00038 Time_Lock_Main.lock();//Appling lock for critial section 00039 if(Log_Value == 1){pc.printf("In LCD_Write_Day Time lock taken\n");} 00040 time_t Time = time(NULL); 00041 tm* Time_Pointer = localtime(&Time); 00042 int Days = Time_Pointer->tm_mday; 00043 Time_Lock_Main.unlock();//Releasing lock for critial section 00044 if(Log_Value == 1){pc.printf("In LCD_Write_Day Time lock released\n");} 00045 stringstream ss; 00046 ss << Days; 00047 string Day_String = ss.str(); 00048 LCD.DDRAM_Address(0x00); 00049 LCD.Write_String("Set Day"); 00050 LCD.DDRAM_Address(0x40); 00051 LCD.Write_String(Day_String); 00052 } 00053 void LCD_Write_Hour() 00054 { 00055 Time_Lock_Main.lock();//Appling lock for critial section 00056 if(Log_Value == 1){pc.printf("In LCD_Write_Hour Time lock taken\n");} 00057 time_t Time = time(NULL); 00058 tm* Time_Pointer = localtime(&Time); 00059 int Hours = Time_Pointer->tm_hour; 00060 Time_Lock_Main.unlock();//Releasing lock for critial section 00061 if(Log_Value == 1){pc.printf("In LCD_Write_Hour Time lock released\n");} 00062 stringstream ss; 00063 ss << Hours; 00064 string Hour_String = ss.str(); 00065 LCD.DDRAM_Address(0x00); 00066 LCD.Write_String("Set Hour"); 00067 LCD.DDRAM_Address(0x40); 00068 LCD.Write_String(Hour_String); 00069 } 00070 void LCD_Write_Minute() 00071 { 00072 Time_Lock_Main.lock();//Appling lock for critial section 00073 if(Log_Value == 1){pc.printf("In LCD_Write_Minute Time lock taken\n");} 00074 time_t Time = time(NULL); 00075 tm* Time_Pointer = localtime(&Time); 00076 int Minutes = Time_Pointer->tm_min; 00077 Time_Lock_Main.unlock();//Releasing lock for critial section 00078 if(Log_Value == 1){pc.printf("In LCD_Write_Minute Time lock released\n");} 00079 stringstream ss; 00080 ss << Minutes; 00081 string Minute_String = ss.str(); 00082 LCD.DDRAM_Address(0x00); 00083 LCD.Write_String("Set Minute"); 00084 LCD.DDRAM_Address(0x40); 00085 LCD.Write_String(Minute_String); 00086 } 00087 void LCD_Write_Seconds() 00088 { 00089 Time_Lock_Main.lock();//Appling lock for critial section 00090 if(Log_Value == 1){pc.printf("In LCD_Write_Seconds Time lock taken\n");} 00091 time_t Time = time(NULL); 00092 tm* Time_Pointer = localtime(&Time); 00093 int Seconds = Time_Pointer->tm_sec; 00094 Time_Lock_Main.unlock();//Releasing lock for critial section 00095 if(Log_Value == 1){pc.printf("In LCD_Write_Seconds Time lock released\n");} 00096 stringstream ss; 00097 ss << Seconds; 00098 string Second_String = ss.str(); 00099 LCD.DDRAM_Address(0x00); 00100 LCD.Write_String("Set Second"); 00101 LCD.DDRAM_Address(0x40); 00102 LCD.Write_String(Second_String); 00103 } 00104 00105 00106 void LCD_Print_Output() 00107 { 00108 00109 if(mode == 0)//Default mode 00110 { 00111 if(Log_Value == 1){pc.printf("In Default Mode\n");} 00112 00113 Thread::wait(Default_Mode_Toggle_Time);//Wait for this amount of time 00114 if(Log_Value == 1){pc.printf("Writing Data to LCD\n");} 00115 sprintf (LCD_buffer, "%1.1f %1.0f %1.2f",Data_Active.get_temperature(),Data_Active.get_pressure(),Data_Active.get_light());//Used for converting to a sting 00116 00117 LCD.DDRAM_Address(0x00); 00118 LCD.Write_String("Temp Pres Lite"); 00119 LCD.DDRAM_Address(0x40); 00120 LCD.Write_String(LCD_buffer);//Print out current data values to the LCD 00121 00122 Thread::wait(Default_Mode_Toggle_Time); //Wait for this amount of time 00123 if(Log_Value == 1){pc.printf("Writing Time and Date to LCD\n");} 00124 Time_Lock_Main.lock();//lock Time_lock for critial section 00125 time_t Time = Data_Active.get_time(); 00126 tm* Time_Pointer = localtime(&Time); 00127 LCD.Display_Clear(); 00128 sprintf (LCD_buffer, "%02d:%02d %02d,%d",Time_Pointer->tm_hour,Time_Pointer->tm_min,(Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900));//Used for converting to a sting 00129 Time_Lock_Main.unlock();//unlock Time_lock for critial section 00130 00131 LCD.DDRAM_Address(0x00); 00132 LCD.Write_String("Current Time:"); 00133 LCD.DDRAM_Address(0x40); 00134 LCD.Write_String(LCD_buffer);//Print the current time to the LCD 00135 00136 if(Log_Value == 1){pc.printf("Checking Switches for next mode\n");} 00137 if(SW1.read() & SW2.read() == 1) 00138 { 00139 mode = 1; 00140 } 00141 } 00142 else if(mode == 1)//Choose either date setting or time setting 00143 { 00144 if(Log_Value == 1){pc.printf("Choose Time or Date Mode 1\n");} 00145 LCD.Display_Clear(); 00146 while(1) 00147 { 00148 LCD.DDRAM_Address(0x00); 00149 LCD.Write_String("Date Time"); 00150 LCD.DDRAM_Address(0x40); 00151 LCD.Write_String("< >"); 00152 Thread::wait(1000); 00153 if(Log_Value == 1){pc.printf("Checking SW1 to go to Date setting\n");} 00154 if(SW1.read() == 1 & SW2.read() == 0) 00155 { 00156 mode = 2;//Date Setting 00157 break; 00158 } 00159 if(Log_Value == 1){pc.printf("Checking SW2 to go to Time setting\n");} 00160 if(SW2.read() == 1 & SW1.read() == 0) 00161 { 00162 mode = 5;//Time Setting 00163 break; 00164 } 00165 } 00166 } 00167 else if(mode == 2)//Set the Year 00168 { 00169 if(Log_Value == 1){pc.printf("In Year Setting Mode\n");} 00170 LCD.Display_Clear(); 00171 while(1) 00172 { 00173 LCD_Write_Year(); 00174 Thread::wait(1000); 00175 if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go to Month setting\n");} 00176 if(SW1.read() & SW2.read() == 1) 00177 { 00178 mode = 3; 00179 break; 00180 } 00181 if(Log_Value == 1){pc.printf("Checking SW1 to add Year\n");} 00182 if(SW1.read() == 1 & SW2.read() == 0) 00183 { 00184 Add_Year(); 00185 } 00186 if(Log_Value == 1){pc.printf("Checking SW2 to subtract Year\n");} 00187 else if(SW2.read() == 1 & SW1.read() == 0) 00188 { 00189 Subtract_Year(); 00190 } 00191 LCD_Write_Year(); 00192 } 00193 } 00194 else if(mode == 3)//Set the Month 00195 { 00196 if(Log_Value == 1){pc.printf("In Month Setting Mode\n");} 00197 LCD.Display_Clear(); 00198 while(1) 00199 { 00200 LCD_Write_Month(); 00201 Thread::wait(1000); 00202 if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go to Day setting\n");} 00203 if(SW1.read() & SW2.read() == 1) 00204 { 00205 mode = 4; 00206 break; 00207 } 00208 if(Log_Value == 1){pc.printf("Checking SW1 to add Month\n");} 00209 if(SW1.read() == 1 & SW2.read() == 0) 00210 { 00211 Add_Month(); 00212 } 00213 if(Log_Value == 1){pc.printf("Checking SW2 to subtract Month\n");} 00214 else if(SW2.read() == 1 & SW1.read() == 0) 00215 { 00216 Subtract_Month(); 00217 } 00218 00219 } 00220 } 00221 else if(mode == 4)//Set the Day 00222 { 00223 if(Log_Value == 1){pc.printf("In Day Setting Mode\n");} 00224 LCD.Display_Clear(); 00225 while(1) 00226 { 00227 LCD_Write_Day(); 00228 Thread::wait(1000); 00229 if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Default setting\n");} 00230 if(SW1.read() & SW2.read() == 1) 00231 { 00232 mode = 0; 00233 break; 00234 } 00235 if(Log_Value == 1){pc.printf("Checking SW1 to add Day\n");} 00236 if(SW1.read() == 1 & SW2.read() == 0) 00237 { 00238 Add_Day(); 00239 } 00240 if(Log_Value == 1){pc.printf("Checking SW2 to subtract Day\n");} 00241 else if(SW2.read() == 1 & SW1.read() == 0) 00242 { 00243 Subtract_Day(); 00244 } 00245 } 00246 } 00247 else if(mode == 5)//Set the Hour 00248 { 00249 if(Log_Value == 1){pc.printf("In Hour Setting Mode\n");} 00250 LCD.Display_Clear(); 00251 while(1) 00252 { 00253 LCD_Write_Hour(); 00254 Thread::wait(1000); 00255 if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Minute setting\n");} 00256 if(SW1.read() & SW2.read() == 1) 00257 { 00258 mode = 6; 00259 break; 00260 } 00261 if(Log_Value == 1){pc.printf("Checking SW1 to add Hour\n");} 00262 if(SW1.read() == 1 & SW2.read() == 0) 00263 { 00264 Add_Hour(); 00265 } 00266 if(Log_Value == 1){pc.printf("Checking SW2 to subtract Hour\n");} 00267 else if(SW2.read() == 1 & SW1.read() == 0) 00268 { 00269 Subtract_Hour(); 00270 } 00271 } 00272 } 00273 else if(mode == 6)//Set the Minute 00274 { 00275 if(Log_Value == 1){pc.printf("In Minute Setting Mode\n");} 00276 LCD.Display_Clear(); 00277 while(1) 00278 { 00279 LCD_Write_Minute(); 00280 Thread::wait(1000); 00281 if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Seconds setting\n");} 00282 if(SW1.read() & SW2.read() == 1) 00283 { 00284 mode = 7; 00285 break; 00286 } 00287 if(Log_Value == 1){pc.printf("Checking SW1 to add Minute\n");} 00288 if(SW1.read() == 1 & SW2.read() == 0) 00289 { 00290 Add_Minute(); 00291 } 00292 if(Log_Value == 1){pc.printf("Checking SW2 to subtract Minute\n");} 00293 else if(SW2.read() == 1 & SW1.read() == 0) 00294 { 00295 Subtract_Minute(); 00296 } 00297 } 00298 } 00299 else if(mode == 7)//Set the Seconds 00300 { 00301 if(Log_Value == 1){pc.printf("In Second Setting Mode\n");} 00302 LCD.Display_Clear(); 00303 while(1) 00304 { 00305 LCD_Write_Seconds(); 00306 Thread::wait(1000); 00307 if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Default setting\n");} 00308 if(SW1.read() & SW2.read() == 1) 00309 { 00310 mode = 0; 00311 break; 00312 } 00313 if(Log_Value == 1){pc.printf("Checking SW1 to add Second\n");} 00314 if(SW1.read() == 1 & SW2.read() == 0) 00315 { 00316 Add_Second(); 00317 } 00318 if(Log_Value == 1){pc.printf("Checking SW1 to subtract Second\n");} 00319 else if(SW2.read() == 1 & SW1.read() == 0) 00320 { 00321 Subtract_Second(); 00322 } 00323 } 00324 } 00325 else 00326 { 00327 if(Log_Value == 1){pc.printf("Mode Error occured mode now set to 0\n");} 00328 mode = 0; 00329 } 00330 } 00331 00332 00333
Generated on Sun Jul 31 2022 05:12:27 by
1.7.2