ELEC
Dependencies: BME280 BMP280 TextLCD mbed
date.h
00001 #include "mbed.h" 00002 DigitalIn sw1(PE_12); 00003 DigitalIn sw2(PE_14); 00004 int d = 0,dd = 0,m = 0,mm = 0,y = 0,yy = 0,yyy = 0,yyyy = 0, pointer = 0, h = 0, hh = 0, mi = 0, mmi = 0, s = 0, ss = 0; 00005 TextLCD lcd(D9,D8,D7,D6,D4,D2); 00006 00007 void display_date() 00008 { 00009 lcd.locate(0,0); 00010 lcd.printf("%i", d); 00011 lcd.locate(1,0); 00012 lcd.printf("%i", dd); 00013 lcd.locate(3,0); 00014 lcd.printf("%i", m); 00015 lcd.locate(4,0); 00016 lcd.printf("%i", mm); 00017 lcd.locate(6,0); 00018 lcd.printf("%i", y); 00019 lcd.locate(7,0); 00020 lcd.printf("%i", yy); 00021 lcd.locate(8,0); 00022 lcd.printf("%i", yyy); 00023 lcd.locate(9,0); 00024 lcd.printf("%i", yyyy); 00025 lcd.locate(0,1); 00026 lcd.printf("%i", h); 00027 lcd.locate(1,1); 00028 lcd.printf("%i", hh); 00029 lcd.locate(3,1); 00030 lcd.printf("%i", mi); 00031 lcd.locate(4,1); 00032 lcd.printf("%i", mmi); 00033 lcd.locate(6,1); 00034 lcd.printf("%i", s); 00035 lcd.locate(7,1); 00036 lcd.printf("%i", ss); 00037 } 00038 00039 void display_time() 00040 { 00041 lcd.locate(0,1); 00042 lcd.printf("%i", h); 00043 lcd.locate(1,1); 00044 lcd.printf("%i", hh); 00045 lcd.locate(2,1); 00046 lcd.printf(":"); 00047 lcd.locate(3,1); 00048 lcd.printf("%i", mi); 00049 lcd.locate(4,1); 00050 lcd.printf("%i", mmi); 00051 lcd.locate(5,1); 00052 lcd.printf(":"); 00053 lcd.locate(6,1); 00054 lcd.printf("%i", s); 00055 lcd.locate(7,1); 00056 lcd.printf("%i", ss); 00057 } 00058 00059 00060 void update_date_and_time() 00061 { 00062 if (pointer == 0) 00063 { 00064 lcd.locate(0,0); 00065 lcd.printf("%i", d); 00066 } 00067 00068 if (pointer == 1) 00069 { 00070 lcd.locate(1,0); 00071 lcd.printf("%i", dd); 00072 } 00073 00074 if (pointer == 2) 00075 { 00076 lcd.locate(3,0); 00077 lcd.printf("%i", m); 00078 } 00079 00080 if (pointer == 3) 00081 { 00082 lcd.locate(4,0); 00083 lcd.printf("%i", mm); 00084 } 00085 00086 if (pointer == 4) 00087 { 00088 lcd.locate(6,0); 00089 lcd.printf("%i", y); 00090 } 00091 00092 if (pointer == 5) 00093 { 00094 lcd.locate(7,0); 00095 lcd.printf("%i", yy); 00096 } 00097 if (pointer == 6) 00098 { 00099 lcd.locate(8,0); 00100 lcd.printf("%i", yyy); 00101 } 00102 00103 if (pointer == 7) 00104 { 00105 lcd.locate(9,0); 00106 lcd.printf("%i", yyyy); 00107 } 00108 if (pointer == 8) 00109 { 00110 lcd.locate(0,1); 00111 lcd.printf("%i", h); 00112 } 00113 if (pointer == 9) 00114 { 00115 lcd.locate(1,1); 00116 lcd.printf("%i", hh); 00117 } 00118 00119 if (pointer == 10) 00120 { 00121 lcd.locate(3,1); 00122 lcd.printf("%i", mi); 00123 } 00124 if (pointer == 11) 00125 { 00126 lcd.locate(4,1); 00127 lcd.printf("%i", mmi); 00128 } 00129 if (pointer == 12) 00130 { 00131 lcd.locate(6,1); 00132 lcd.printf("%i", s); 00133 } 00134 00135 if (pointer == 13) 00136 { 00137 lcd.locate(7,1); 00138 lcd.printf("%i", ss); 00139 } 00140 } 00141 00142 void select_date() 00143 { 00144 if (sw2 == 1) 00145 { 00146 wait (1); 00147 pointer++; 00148 } 00149 else if(pointer != 14) 00150 { 00151 switch (pointer) 00152 { 00153 case 0: 00154 if (sw1 == 1) 00155 { 00156 wait (1); 00157 d++; 00158 if (d == 4) 00159 { 00160 d = 0; 00161 } 00162 } 00163 case 1: 00164 if (sw1 == 1) 00165 { 00166 wait (1); 00167 dd++; 00168 if (dd == 10) 00169 { 00170 dd = 0; 00171 } 00172 } 00173 case 2: 00174 if (sw1 == 1) 00175 { 00176 wait (1); 00177 m++; 00178 if (m == 2) 00179 { 00180 m = 0; 00181 } 00182 } 00183 case 3: 00184 if (sw1 == 1) 00185 { 00186 wait (1); 00187 mm++; 00188 if (mm == 10) 00189 { 00190 mm = 0; 00191 } 00192 } 00193 case 4: 00194 if (sw1 == 1) 00195 { 00196 wait (1); 00197 y++; 00198 if (y == 3) 00199 { 00200 y = 0; 00201 } 00202 } 00203 case 5: 00204 if (sw1 == 1) 00205 { 00206 wait (1); 00207 yy++; 00208 if (yy == 10) 00209 { 00210 yy = 0; 00211 } 00212 } 00213 case 6: 00214 if (sw1 == 1) 00215 { 00216 wait (1); 00217 yyy++; 00218 if (yyy == 10) 00219 { 00220 yyy = 0; 00221 } 00222 } 00223 case 7: 00224 if (sw1 == 1) 00225 { 00226 wait (1); 00227 yyyy++; 00228 if (yyyy == 10) 00229 { 00230 yyyy = 0; 00231 } 00232 } 00233 case 8: 00234 if (sw1 == 1) 00235 { 00236 wait (1); 00237 h++; 00238 if (h== 3) 00239 { 00240 h = 0; 00241 } 00242 } 00243 case 9: 00244 if (sw1 == 1) 00245 { 00246 wait (1); 00247 hh++; 00248 if (hh == 4) 00249 { 00250 hh = 0; 00251 } 00252 } 00253 case 10: 00254 if (sw1 == 1) 00255 { 00256 wait (1); 00257 mi++; 00258 if (mi == 6) 00259 { 00260 mi = 0; 00261 } 00262 } 00263 case 11: 00264 if (sw1 == 1) 00265 { 00266 wait (1); 00267 mmi++; 00268 if (mmi == 10) 00269 { 00270 mmi = 0; 00271 } 00272 } 00273 case 12: 00274 if (sw1 == 1) 00275 { 00276 wait (1); 00277 s++; 00278 if (s == 6) 00279 { 00280 s = 0; 00281 } 00282 } 00283 case 13: 00284 if (sw1 == 1) 00285 { 00286 wait (1); 00287 ss++; 00288 if (ss == 10) 00289 { 00290 ss = 0; 00291 } 00292 } 00293 00294 00295 00296 } 00297 } 00298 update_date_and_time(); 00299 } 00300 00301 00302 00303 00304 00305 00306
Generated on Mon Aug 15 2022 09:14:07 by
1.7.2