Calvin Kalintra / Mbed 2 deprecated CW

Dependencies:   BME280 BMP280 TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers date.h Source File

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