Arduino GLCD Clock

One of my earlier Arduino projects made use of a large 64X128 LCD module controlled by the KS0108 chipset. The real time clock chip used to keep the time was a Dallas Semi DS1307.  With the coin battery I used for backup on the DS1307, I can keep the clock from needing adjustment  for about 5 years.  Power for the clock is supplied from a 12V external wall wart.  The first version of the clock just displayed the time and the date. I later updated the code to include a second screen to show upcoming holidays and a third screen to display holidays for the particular calendar day.

Below is a picture of the clock in operation. The case is a quick and dirty build made from four brass screws, a piece of acrylic, and a short section of 2″x4″ lumber. To create the body made from 2″x4″ lumber I cut a section of lumber, chucked it in myCNC  milling machine and milled out a square pocket the approximate size of the electronics assembly.  I used a piece of packing foam placed behind the electronics to push the display up against the acrylic.

GLCDClock_running

GLCD Clock

Inside the clock you can see the main daughter board that attaches to the display.   The maind daughter board has the Atmega328 (Arduino) chip and a MAX232 serial converter (on backside of board in this pic).  On a second smaller daughter card you can see the DS1307, the quartz oscillator, and battery.

GLCDClock_electronics

GLCD Clock backside image

Here is a picture of all the parts disassembled:

GLCDClock_disassembled

GLCD Clock Disassembled

I didn’t include a way to manually set the clock because I thought I could just set it once and leave it for 5 years. After the first few months of use I found the clock was loosing time at a rate of about a half a minute per month. I think the inaccuracy of the clock was largely due to the temperature inside the case which is slightly higher than room temperature. To correct the time drift, I added a few lines in the code to add or subract a few seconds every month. To figure out how much to set the correction I waited six months, calculated the drift in seconds and divided by six. The reason for the six month wait was to take into account two seasons of temperature variation for the location in the house I had picked. Of course changing the location of the clock would probably change the correction  but I haven’t had a need to move it yet.

Below is the code for the clock. The code uses the glcd.h library to run the display and the Wire.h library to communicate with the DS1307 RTC chip.

 C# |  copy code |? 
001
//// 6 Year Clock With Holidays///
002
//// SIMPLE ROUTINE REQUIRES UPDATE EVERY SO MANY YEARS TO UPDATE LEAP YEAR AND DAYLIGHT SAVINGS TIME CORRECTIONS
003
//// void NextSevenArray NEEDS UPDATE BY 2032
004
//// void CheckDLST NEEDS UPDATE AFTER 12/3/2017
005
////ver notes:  Added monthly seconds corrections////
006
 
007
#include "Wire.h"
008
#define DS1307_I2C_ADDRESS 0x68
009
#include <glcd.h>
010
#include "fonts/allFonts.h"         // system and arial14 fonts are used
011
#include "bitmaps/allBitmaps.h"       // all images in the bitmap dir 
012
 
013
 
014
// Declare array for NextDays Arrays
015
int NextDays[8];
016
int NextMonths[8];
017
int NextYears[8];
018
 
019
 
020
// Declare DS1307 vars so they are global
021
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
022
 
023
// Daylight Savings Time Fall Back Flag ****Only a problem if power is cycled close to DLST****
024
int dlst = 1 ;
025
 
026
// Set flags for holiday screen
027
int holiday = 0;
028
int HolidayToday = 0;
029
 
030
// Create Variable for once a day check
031
int TodaysDay = 0;
032
 
033
// Create variables for future day checks
034
int TomorrowDay = 0;
035
int TomorrowMonth = 0;
036
int TomorrowYear = 0;
037
 
038
// Create variables for holiday check
039
 
040
int DayToCheck = 0;
041
int MonthToCheck = 0;
042
int YearToCheck = 0;
043
 
044
// Create variables for monthly drift correction
045
int AddSecPerMonth = 36; //seconds to add per month (pos if clock is slow, neg is clock is fast - should only be a few seconds//
046
int ThisMonth;
047
 
048
// Convert normal decimal numbers to binary coded decimal
049
byte decToBcd(byte val)
050
{
051
  return ( (val/10*16) + (val%10) );
052
}
053
 
054
// Convert binary coded decimal to normal decimal numbers
055
byte bcdToDec(byte val)
056
{
057
  return ( (val/16*10) + (val%16) );
058
}
059
 
060
// Stops the DS1307, but it has the side effect of setting seconds to 0
061
// Probably only want to use this for testing
062
/*void stopDs1307()
063
{
064
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
065
  Wire.send(0);
066
  Wire.send(0x80);
067
  Wire.endTransmission();
068
}*/
069
 
070
// 1) Sets the date and time on the ds1307
071
// 2) Starts the clock
072
// 3) Sets hour mode to 24 hour clock
073
// Assumes you're passing in valid numbers
074
 
075
void setup()
076
{
077
  GLCD.Init();   // initialise the library, non inverted writes pixels onto a clear screen
078
  Wire.begin();
079
  Serial.begin(9600);
080
 
081
  // Change these values to what you want to set your clock to.
082
  // You probably only want to set your clock once and then remove
083
  // the setDateDs1307 call.
084
  // Daylight Savings Time Flag
085
  second = 00;
086
  minute = 26;
087
  hour = 20;
088
  dayOfWeek = 4; //Sunday is 1
089
  dayOfMonth = 15;
090
  month = 2;
091
  year = 12;
092
 
093
//***ENABLE THE FOLLOWING LINE FOR CLOCK SETTING ONLY****////  
094
//setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
095
 
096
//read current month and set ThisMonth to monitor monthly change.  
097
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
098
ThisMonth = month;
099
 
100
//CREATE INITAL 7 DAY ARRAY FOR WEEK SCHEDULE
101
NextSevenArray();
102
}
103
 
104
void  loop()
105
{
106
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
107
 
108
//Start once a month check//
109
if (ThisMonth != month)//Run this loop once on month change
110
  {
111
  second = second + AddSecPerMonth;
112
  setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
113
  ThisMonth = month;
114
  }
115
//end once a month check//
116
 
117
// Start once a day check//
118
if (dayOfMonth != TodaysDay)
119
  {
120
 
121
  CheckResetClock(); //Check to see if it is time to enter new data for holidays and DLST
122
 
123
  NextSevenArray(); //Generate 7 day array
124
 
125
  holiday = 0; //Set holiday flag to 0 
126
  HolidayToday = 0;// Set HolidayToday flag to 0 
127
  DayToCheck = NextDays[0];
128
  MonthToCheck = NextMonths[0];
129
  YearToCheck = NextYears[0];
130
  GLCD.ClearScreen();
131
  GLCD.SelectFont(SystemFont5x7);
132
  GLCD.println("Checking Calendar:");
133
  CheckHoliday();// Run holiday void for HolidayToday flag
134
  if (holiday == 1)
135
    {
136
    HolidayToday = 1;  
137
    } 
138
  holiday = 0; //reset holiday flag to 0  
139
  for (int i=1; i <= 7; i++) //Run holiday Void for next six days in 7 day array to set holiday flag
140
    {
141
    DayToCheck = NextDays[i];
142
    MonthToCheck = NextMonths[i];
143
    YearToCheck = NextYears[i];
144
    CheckHoliday();
145
    } 
146
  GLCD.ClearScreen();//clear screen of any holiday messages that pop up
147
 
148
  if (holiday == 0 && HolidayToday == 0)// if no holidays or upcoming holidays print the calendar so only the clock has to update
149
    {
150
    PrintCalendar();  
151
    }
152
  }
153
TodaysDay = dayOfMonth;
154
// End once a day check//
155
 
156
// Start DLST Check  -- Delete these lines if DLST is not observed//
157
if (hour == 2 && minute == 0)
158
  {
159
  CheckDLST(); //Check For Daylight Savings Time 
160
  }
161
// End DLST Check//
162
//
163
//Start print coming holidays//
164
if (holiday == 1 && HolidayToday == 1)
165
  {
166
  GLCD.ClearScreen();//Clear Screen
167
  DayToCheck = NextDays[0];
168
  MonthToCheck = NextMonths[0];
169
  YearToCheck = NextYears[0];
170
  GLCD.CursorToXY(2,0);
171
  GLCD.SelectFont(SystemFont5x7);
172
  GLCD.println("     TODAY IS:");
173
  GLCD.println();
174
  CheckHoliday(); //Check for todays holidays and print if there is one or more
175
  delay(4000);
176
  GLCD.ClearScreen();//Clear Screen
177
  GLCD.SelectFont(SystemFont5x7);
178
  GLCD.CursorToXY(2,0);
179
  GLCD.println("     COMING UP:");
180
  GLCD.println();
181
  for (int i=1; i <= 7; i++)
182
  {
183
    DayToCheck = NextDays[i];
184
    MonthToCheck = NextMonths[i];
185
    CheckHoliday(); 
186
  }
187
  delay(4000); //Display for 5 seconds before next loop
188
  GLCD.ClearScreen();//Clear Screen
189
  PrintCalendar(); 
190
  PrintClock();
191
  delay(10000);
192
  }
193
else if (holiday == 0 && HolidayToday == 1)
194
  {  
195
  GLCD.ClearScreen();//Clear Screen
196
  DayToCheck = NextDays[0];
197
  MonthToCheck = NextMonths[0];
198
  YearToCheck = NextYears[0];
199
  GLCD.CursorToXY(2,0);
200
  GLCD.SelectFont(SystemFont5x7);
201
  GLCD.println("     TODAY IS:");
202
  GLCD.println();
203
  CheckHoliday(); //Check for todays holidays and print if there is one or more
204
  holiday = 0; // Reset holiday flag only in this instance***
205
  delay(4000); //Display for 5 seconds before next loop
206
  GLCD.ClearScreen();//Clear Screen
207
  PrintCalendar(); 
208
  PrintClock();
209
  delay(10000);
210
  }
211
else if (holiday == 1 && HolidayToday == 0)
212
  {
213
  GLCD.ClearScreen();//Clear Screen
214
  GLCD.SelectFont(SystemFont5x7);
215
  GLCD.CursorToXY(2,0);
216
  GLCD.println("     COMING UP:");
217
  GLCD.println();
218
  for (int i=1; i <= 7; i++)
219
  {
220
    DayToCheck = NextDays[i];
221
    MonthToCheck = NextMonths[i];
222
    CheckHoliday(); 
223
  }
224
  delay(4000); //Display for 5 seconds before next loop
225
  GLCD.ClearScreen();//Clear Screen
226
  PrintCalendar(); 
227
  PrintClock();
228
  delay(10000);
229
  }
230
else
231
  {
232
  PrintClock();
233
  delay(10000); 
234
  }
235
} 
236
 
237
 
238
 
239
//////////////////////////////////////////////////////////////////////////////
240
void setDateDs1307(byte second,        // 0-59
241
                   byte minute,        // 0-59
242
                   byte hour,          // 1-23
243
                   byte dayOfWeek,     // 1-7
244
                   byte dayOfMonth,    // 1-28/29/30/31
245
                   byte month,         // 1-12
246
                   byte year)          // 0-99
247
{
248
   Wire.beginTransmission(DS1307_I2C_ADDRESS);
249
   Wire.send(0);
250
   Wire.send(decToBcd(second));    // 0 to bit 7 starts the clock
251
   Wire.send(decToBcd(minute));
252
   Wire.send(decToBcd(hour));      // If you want 12 hour am/pm you need to set
253
                                   // bit 6 (also need to change readDateDs1307)
254
   Wire.send(decToBcd(dayOfWeek));
255
   Wire.send(decToBcd(dayOfMonth));
256
   Wire.send(decToBcd(month));
257
   Wire.send(decToBcd(year));
258
   Wire.endTransmission();
259
}
260
 
261
void getDateDs1307(byte *second,
262
          byte *minute,
263
          byte *hour,
264
          byte *dayOfWeek,
265
          byte *dayOfMonth,
266
          byte *month,
267
          byte *year)
268
{
269
  // Reset the register pointer
270
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
271
  Wire.send(0);
272
  Wire.endTransmission();
273
 
274
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
275
 
276
  // A few of these need masks because certain bits are control bits
277
  *second     = bcdToDec(Wire.receive() & 0x7f);
278
  *minute     = bcdToDec(Wire.receive());
279
  *hour       = bcdToDec(Wire.receive() & 0x3f);  // Need to change this if 12 hour am/pm
280
  *dayOfWeek  = bcdToDec(Wire.receive());
281
  *dayOfMonth = bcdToDec(Wire.receive());
282
  *month      = bcdToDec(Wire.receive());
283
  *year       = bcdToDec(Wire.receive());
284
}
285
 
286
 
287
void CheckResetClock()
288
{
289
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
290
//CHECK FOR TIME to reprogram clock
291
 
292
  if (month >= 11 && year >= 17)  {
293
    GLCD.ClearScreen();
294
    GLCD.CursorToXY(2,0);
295
    GLCD.SelectFont(SystemFont5x7);
296
    GLCD.println("REPROGRAM CLOCK");
297
    delay(1500000);
298
}  
299
 
300
 
301
}  
302
void CheckDLST() 
303
{
304
//CHECK FOR DAYLIGHT SAVINGS TIME - disable section if DLST is not observed
305
//Spring Forward Date
306
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
307
 
308
if ((minute == 0 && hour == 2 && dayOfMonth == 11 && month == 3 && year == 12) ||
309
  (minute == 0 && hour == 2 && dayOfMonth == 10 && month == 3 && year == 13) ||
310
  (minute == 0 && hour == 2 && dayOfMonth == 9 && month == 3 && year == 14) ||
311
  (minute == 0 && hour == 2 && dayOfMonth == 8 && month == 3 && year == 15) ||
312
  (minute == 0 && hour == 2 && dayOfMonth == 13 && month == 3 && year == 16) ||
313
  (minute == 0 && hour == 2 && dayOfMonth == 12 && month == 3 && year == 17))  {
314
  setDateDs1307(second,0,3, dayOfWeek, dayOfMonth, month, year);
315
  dlst = 1;
316
  }
317
//Fall Back Dates
318
if ((minute == 0 && hour == 2 && dayOfMonth == 6 && month == 11 && year == 11 && dlst == 1) ||
319
  (minute == 0 && hour == 2 && dayOfMonth == 4 && month == 11 && year == 12 && dlst == 1) ||
320
  (minute == 0 && hour == 2 && dayOfMonth == 3 && month == 11 && year == 13 && dlst == 1) ||
321
  (minute == 0 && hour == 2 && dayOfMonth == 2 && month == 11 && year == 14 && dlst == 1) ||
322
  (minute == 0 && hour == 2 && dayOfMonth == 1 && month == 11 && year == 15 && dlst == 1) ||
323
  (minute == 0 && hour == 2 && dayOfMonth == 6 && month == 11 && year == 16 && dlst == 1) ||
324
  (minute == 0 && hour == 2 && dayOfMonth == 5 && month == 11 && year == 17 && dlst == 1))  {
325
  setDateDs1307(second,0,1, dayOfWeek, dayOfMonth, month, year);
326
  dlst = 0;
327
  }        
328
}
329
 
330
void PrintCalendar()
331
{
332
// PRINT GENERAL CALENDAR DISPLAY  
333
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
334
 
335
// PRINT DAY OF WEEK SUN = 1  
336
  GLCD.SelectFont(CalLite24);
337
  if (dayOfWeek == 1)  {
338
      GLCD.CursorToXY(19,0);
339
      GLCD.print("SUNDAY");
340
  }
341
  else if (dayOfWeek == 2)  {
342
      GLCD.CursorToXY(18,0);
343
      GLCD.print("MONDAY");
344
  }
345
  else if (dayOfWeek == 3)  {
346
      GLCD.CursorToXY(11,0);
347
      GLCD.print("TUESDAY");
348
  }       
349
  else if (dayOfWeek == 4)  {
350
      GLCD.CursorToXY(2,0);
351
      GLCD.print("WEDNESDY");
352
  }      
353
  else if (dayOfWeek == 5)  {
354
      GLCD.CursorToXY(4,0);
355
      GLCD.print("THURSDAY");
356
  }      
357
  else if (dayOfWeek == 6)  {
358
      GLCD.CursorToXY(25,0);
359
      GLCD.print("FRIDAY");
360
  }      
361
  else if (dayOfWeek == 7)  {
362
      GLCD.CursorToXY(3,0);
363
      GLCD.print("SATURDAY");
364
  }      
365
 
366
// PRINT MONTH
367
  GLCD.SelectFont(CalLite24);
368
 
369
  if (month == 1)  {
370
      GLCD.CursorToXY(32,20);
371
      GLCD.print("JAN ");
372
  }
373
  else if (month == 2)  {
374
      GLCD.CursorToXY(27,20);
375
      GLCD.print("FEB ");
376
  }
377
  else if (month == 3)  {
378
      GLCD.CursorToXY(27,20);
379
      GLCD.print("MAR ");
380
  }  
381
  else if (month == 4)  {
382
      GLCD.CursorToXY(20,20);
383
      GLCD.print("APRIL ");
384
  }  
385
  else if (month == 5)  {
386
      GLCD.CursorToXY(27,20);
387
      GLCD.print("MAY ");
388
  }  
389
  else if (month == 6)  {
390
      GLCD.CursorToXY(27,20);
391
      GLCD.print("JUN ");
392
  }  
393
  else if (month == 7)  {
394
      GLCD.CursorToXY(27,20);
395
      GLCD.print("JULY ");
396
  }  
397
  else if (month == 8)  {
398
      GLCD.CursorToXY(27,20);
399
      GLCD.print("AUG ");
400
  }
401
  else if (month == 9)  {
402
      GLCD.CursorToXY(25,20);
403
      GLCD.print("SEPT ");
404
  }
405
  else if (month == 10)  {
406
      GLCD.CursorToXY(27,20);
407
      GLCD.print("OCT ");
408
  }
409
  else if (month == 11)  {
410
      GLCD.CursorToXY(27,20);
411
      GLCD.print("NOV ");
412
  }
413
  else if (month == 12)  {
414
      GLCD.CursorToXY(27,20);
415
      GLCD.print("DEC ");
416
  }
417
 
418
// PRINT DAY OF MONTH ON SAME LINE
419
  GLCD.print(dayOfMonth, DEC); 
420
}
421
 
422
void PrintClock()
423
{
424
// PRINT TIME
425
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
426
GLCD.SelectFont(CalLite24);
427
GLCD.CursorToXY(20,42);
428
 
429
GLCD.EraseTextLine(eraseFULL_LINE);
430
 
431
GLCD.CursorToXY(20,42);
432
 
433
  if (hour == 0)  {
434
  GLCD.print("12");     
435
  }
436
  else if (hour > 12)  {
437
    if ((hour - 12) < 10)  {
438
    GLCD.print("0");  
439
 
440
    }  
441
  GLCD.print(hour - 12, DEC);
442
  }
443
  else {
444
  GLCD.print(hour, DEC);  
445
  }  
446
 
447
  GLCD.print(":");
448
  if (minute < 10)  {
449
  GLCD.print("0");
450
  }
451
  GLCD.print(minute, DEC);
452
  GLCD.print(" ");
453
 
454
  if (hour < 12)  {
455
  GLCD.print("AM");     
456
  }
457
  else  {
458
  GLCD.print("PM");
459
  }  
460
}
461
 
462
 
463
 
464
void tomorrow () 
465
{
466
//Generate values for TomorrowDay, TomorrowMonth, and TomorrowYear
467
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
468
 
469
if (month == 12 && dayOfMonth == 31)
470
  {
471
  TomorrowDay = 1;
472
  TomorrowMonth = 1;
473
  TomorrowYear = year + 1;
474
  }
475
else if (month == 2 && dayOfMonth == 29)///ds1307 compensates for leap year
476
  {
477
  TomorrowDay = 1;
478
  TomorrowMonth = 3;
479
  TomorrowYear = year;
480
  }
481
else if (month == 2 && dayOfMonth == 28)
482
  {
483
  TomorrowDay = 1;
484
  TomorrowMonth = 3;
485
  TomorrowYear = year;
486
  }
487
else if ((month == 4 || month == 6 || month == 9 || month == 11)&& dayOfMonth == 30)
488
  {
489
  TomorrowDay = 1;
490
  TomorrowMonth = month +1 ;
491
  TomorrowYear = year;
492
  }
493
else if ((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10)&& dayOfMonth == 31)
494
  {
495
  TomorrowDay = 1;
496
  TomorrowMonth = month +1 ;
497
  TomorrowYear = year;
498
  }
499
else 
500
  {
501
  TomorrowDay = dayOfMonth + 1;
502
  TomorrowMonth = month;
503
  TomorrowYear = year;
504
  }
505
}
506
 
507
void CheckHoliday() 
508
{
509
//CHECK FOR REGULAR HOLIDAY
510
//BIRTHDAYS FIRST
511
 
512
 
513
if (DayToCheck == 3 && MonthToCheck == 20)  {
514
    GLCD.SelectFont(SystemFont5x7);
515
    GLCD.println("3/20-JOE'S BIRTHDAY");
516
    holiday = 1;
517
}
518
 
519
if (DayToCheck == 24 && MonthToCheck == 12)  {
520
    GLCD.SelectFont(SystemFont5x7);
521
    GLCD.println("12/24-CHRISTMAS EVE");
522
    holiday = 1;
523
}
524
if (DayToCheck == 25 && MonthToCheck == 12)  {
525
    GLCD.SelectFont(SystemFont5x7);
526
    GLCD.println("12/25-CHRISTMAS DAY");
527
    holiday = 1;
528
}
529
if (DayToCheck == 31 && MonthToCheck == 12)  {
530
    GLCD.SelectFont(SystemFont5x7);
531
    GLCD.println("12/31-NEW YEARS EVE");
532
    holiday = 1;
533
}
534
if (DayToCheck == 1 && MonthToCheck == 1)  {
535
    GLCD.SelectFont(SystemFont5x7);
536
    GLCD.println("1/1-NEW YEARS DAY");
537
    holiday = 1;
538
}
539
if (DayToCheck == 1 && MonthToCheck == 15)  {
540
    GLCD.SelectFont(SystemFont5x7);
541
    GLCD.println("1/15-MARTIN L.K.'S BDAY");
542
    holiday = 1;
543
}
544
if (DayToCheck == 22 && MonthToCheck == 2)  {
545
    GLCD.SelectFont(SystemFont5x7);
546
    GLCD.println("2/22-WASHINGTON'S BDAY");
547
    holiday = 1;
548
}
549
if (DayToCheck == 12 && MonthToCheck == 2)  {
550
    GLCD.SelectFont(SystemFont5x7);
551
    GLCD.println("2/12-LINCOLN'S BDAY");
552
    holiday = 1;
553
}
554
if (DayToCheck == 17 && MonthToCheck == 3)  {
555
    GLCD.SelectFont(SystemFont5x7);
556
    GLCD.println("3/17-ST. PATRICKS DAY");
557
    holiday = 1;
558
}
559
if (DayToCheck == 2 && MonthToCheck == 2)  {
560
    GLCD.SelectFont(SystemFont5x7);
561
    GLCD.println("2/2-GROUNDHOG DAY");
562
    holiday = 1;
563
}
564
if (DayToCheck == 14 && MonthToCheck == 2)  {
565
    GLCD.SelectFont(SystemFont5x7);
566
    GLCD.println("2/14-VALENTINE'S DAY");
567
    holiday = 1;
568
}
569
if (DayToCheck == 31 && MonthToCheck == 10)  {
570
    GLCD.SelectFont(SystemFont5x7);
571
    GLCD.println("10/31-HALLOWEEN");
572
    holiday = 1;
573
}
574
 
575
//CHECK FOR CALENDAR DEPENDENT HOLIDAY
576
if ((DayToCheck == 24 && MonthToCheck == 11 && YearToCheck == 11) ||
577
    (DayToCheck == 22 && MonthToCheck == 11 && YearToCheck == 12) ||
578
    (DayToCheck == 28 && MonthToCheck == 11 && YearToCheck == 13) ||
579
    (DayToCheck == 27 && MonthToCheck == 11 && YearToCheck == 14) ||
580
    (DayToCheck == 26 && MonthToCheck == 11 && YearToCheck == 15) ||
581
    (DayToCheck == 24 && MonthToCheck == 11 && YearToCheck == 16) ||
582
    (DayToCheck == 23 && MonthToCheck == 11 && YearToCheck == 17) ||
583
    (DayToCheck == 22 && MonthToCheck == 11 && YearToCheck == 18 ))  {
584
    GLCD.SelectFont(SystemFont5x7);
585
    GLCD.print (MonthToCheck);
586
    GLCD.print ("/");
587
    GLCD.print (DayToCheck);
588
    GLCD.println("-THANKSGIVING");
589
    holiday = 1;
590
}
591
if ((DayToCheck == 30 && MonthToCheck == 5 && YearToCheck == 11) ||
592
    (DayToCheck == 28 && MonthToCheck == 5 && YearToCheck == 12) ||
593
    (DayToCheck == 27 && MonthToCheck == 5 && YearToCheck == 13) ||
594
    (DayToCheck == 26 && MonthToCheck == 5 && YearToCheck == 14) ||
595
    (DayToCheck == 25 && MonthToCheck == 5 && YearToCheck == 15) ||
596
    (DayToCheck == 30 && MonthToCheck == 5 && YearToCheck == 16) ||
597
    (DayToCheck == 29 && MonthToCheck == 5 && YearToCheck == 17) ||
598
    (DayToCheck == 28 && MonthToCheck == 5 && YearToCheck == 18 ))  {
599
    GLCD.SelectFont(SystemFont5x7);
600
    GLCD.print (MonthToCheck);
601
    GLCD.print ("/");
602
    GLCD.print (DayToCheck);
603
    GLCD.println("-MEMORIAL DAY");
604
    holiday = 1;
605
}
606
if ((DayToCheck == 11 && MonthToCheck == 11 && YearToCheck == 11) ||
607
    (DayToCheck == 12 && MonthToCheck == 11 && YearToCheck == 12) ||
608
    (DayToCheck == 11 && MonthToCheck == 11 && YearToCheck == 13) ||
609
    (DayToCheck == 11 && MonthToCheck == 11 && YearToCheck == 14) ||
610
    (DayToCheck == 11 && MonthToCheck == 11 && YearToCheck == 15) ||
611
    (DayToCheck == 11 && MonthToCheck == 11 && YearToCheck == 16) ||
612
    (DayToCheck == 10 && MonthToCheck == 11 && YearToCheck == 17) ||
613
    (DayToCheck == 12 && MonthToCheck == 11 && YearToCheck == 18 ))  {
614
    GLCD.SelectFont(SystemFont5x7);
615
    GLCD.print (MonthToCheck);
616
    GLCD.print ("/");
617
    GLCD.print (DayToCheck);
618
    GLCD.println("-VETERANS DAY");
619
    holiday = 1;
620
}
621
if ((DayToCheck == 5 && MonthToCheck == 9 && YearToCheck == 11) ||
622
    (DayToCheck == 3 && MonthToCheck == 9 && YearToCheck == 12) ||
623
    (DayToCheck == 2 && MonthToCheck == 9 && YearToCheck == 13) ||
624
    (DayToCheck == 1 && MonthToCheck == 9 && YearToCheck == 14) ||
625
    (DayToCheck == 7 && MonthToCheck == 9 && YearToCheck == 15) ||
626
    (DayToCheck == 5 && MonthToCheck == 9 && YearToCheck == 16) ||
627
    (DayToCheck == 4 && MonthToCheck == 9 && YearToCheck == 17) ||
628
    (DayToCheck == 3 && MonthToCheck == 9 && YearToCheck == 18 ))  {
629
    GLCD.SelectFont(SystemFont5x7);
630
    GLCD.print (MonthToCheck);
631
    GLCD.print ("/");
632
    GLCD.print (DayToCheck);    
633
    GLCD.println("-LABOR DAY");
634
    holiday = 1;
635
}
636
if ((DayToCheck == 3 && MonthToCheck == 2 && YearToCheck == 11) ||
637
    (DayToCheck == 23 && MonthToCheck == 1 && YearToCheck == 12) ||
638
    (DayToCheck == 10 && MonthToCheck == 2 && YearToCheck == 13) ||
639
    (DayToCheck == 31 && MonthToCheck == 1 && YearToCheck == 14) ||
640
    (DayToCheck == 19 && MonthToCheck == 2 && YearToCheck == 15) ||
641
    (DayToCheck == 8 && MonthToCheck == 2 && YearToCheck == 16) ||
642
    (DayToCheck == 28 && MonthToCheck == 1 && YearToCheck == 17) ||
643
    (DayToCheck == 16 && MonthToCheck == 2 && YearToCheck == 18 ))  {
644
    GLCD.SelectFont(SystemFont5x7);
645
    GLCD.print (MonthToCheck);
646
    GLCD.print ("/");
647
    GLCD.print (DayToCheck);    
648
    GLCD.println("-CHINESE NEW YEAR");
649
    holiday = 1;
650
}
651
if ((DayToCheck == 24 && MonthToCheck == 4 && YearToCheck == 11) ||
652
    (DayToCheck == 8 && MonthToCheck == 4 && YearToCheck == 12) ||
653
    (DayToCheck == 31 && MonthToCheck == 3 && YearToCheck == 13) ||
654
    (DayToCheck == 20 && MonthToCheck == 4 && YearToCheck == 14) ||
655
    (DayToCheck == 5 && MonthToCheck == 4 && YearToCheck == 15) ||
656
    (DayToCheck == 27 && MonthToCheck == 3 && YearToCheck == 16) ||
657
    (DayToCheck == 16 && MonthToCheck == 4 && YearToCheck == 17) ||
658
    (DayToCheck == 1 && MonthToCheck == 4 && YearToCheck == 18 ))  {
659
    GLCD.SelectFont(SystemFont5x7);
660
    GLCD.print (MonthToCheck);
661
    GLCD.print ("/");
662
    GLCD.print (DayToCheck);    
663
    GLCD.println("-EASTER SUNDAY");
664
    holiday = 1;
665
}
666
if ((DayToCheck == 8 && MonthToCheck == 5 && YearToCheck == 11) ||
667
    (DayToCheck == 13 && MonthToCheck == 5 && YearToCheck == 12) ||
668
    (DayToCheck == 12 && MonthToCheck == 5 && YearToCheck == 13) ||
669
    (DayToCheck == 11 && MonthToCheck == 5 && YearToCheck == 14) ||
670
    (DayToCheck == 10 && MonthToCheck == 5 && YearToCheck == 15) ||
671
    (DayToCheck == 8 && MonthToCheck == 5 && YearToCheck == 16) ||
672
    (DayToCheck == 14 && MonthToCheck == 5 && YearToCheck == 17) ||
673
    (DayToCheck == 13 && MonthToCheck == 5 && YearToCheck == 18 ))  {
674
    GLCD.SelectFont(SystemFont5x7);
675
    GLCD.print (MonthToCheck);
676
    GLCD.print ("/");
677
    GLCD.print (DayToCheck);    
678
    GLCD.println("-MOTHER'S DAY");
679
    holiday = 1;
680
}
681
if ((DayToCheck == 19 && MonthToCheck == 6 && YearToCheck == 11) ||
682
    (DayToCheck == 17 && MonthToCheck == 6 && YearToCheck == 12) ||
683
    (DayToCheck == 16 && MonthToCheck == 6 && YearToCheck == 13) ||
684
    (DayToCheck == 15 && MonthToCheck == 6 && YearToCheck == 14) ||
685
    (DayToCheck == 21 && MonthToCheck == 6 && YearToCheck == 15) ||
686
    (DayToCheck == 19 && MonthToCheck == 6 && YearToCheck == 16) ||
687
    (DayToCheck == 18 && MonthToCheck == 6 && YearToCheck == 17) ||
688
    (DayToCheck == 17 && MonthToCheck == 6 && YearToCheck == 18 ))  {
689
    GLCD.SelectFont(SystemFont5x7);
690
    GLCD.print (MonthToCheck);
691
    GLCD.print ("/");
692
    GLCD.print (DayToCheck);    
693
    GLCD.println("-FATHERS'S DAY");
694
    holiday = 1;
695
}
696
 
697
}
698
void NextSevenArray() 
699
{
700
//Generate values for 3 arrays NextDays, NextMonths, and NextYears
701
//Because of simple leap year check only good to 2031
702
//Need to Declare arrays in main program: NextDays, NextMonths, NextYears (int NextDays[7];)
703
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
704
 
705
NextDays[0] = dayOfMonth;
706
NextMonths[0] = month;
707
NextYears[0] = year;
708
 
709
int TestDay = dayOfMonth;
710
int TestMonth = month;
711
int TestYear = year;
712
 
713
for (int i=1; i <= 7; i++)
714
  {
715
  if (TestMonth == 12 && TestDay == 31)
716
    {
717
    TomorrowDay = 1;
718
    TomorrowMonth = 1;
719
    TomorrowYear = TestYear + 1;
720
    }
721
  else if ((TestMonth == 2 && TestDay == 28) && (TestYear != 2012 && TestYear != 2016 && TestYear != 2020 && TestYear != 2024 && TestYear != 2028))///good to 2032
722
    {
723
    TomorrowDay = 29;
724
    TomorrowMonth = 2;
725
    TomorrowYear = TestYear;
726
    }
727
  else if (TestMonth == 2 && TestDay == 29)
728
    {
729
    TomorrowDay = 1;
730
    TomorrowMonth = 3;
731
    TomorrowYear = TestYear;
732
    }
733
  else if (TestMonth == 2 && TestDay == 28)
734
    {
735
    TomorrowDay = 1;
736
    TomorrowMonth = 3;
737
    TomorrowYear = TestYear;
738
    }
739
  else if ((TestMonth == 4 || TestMonth == 6 || TestMonth == 9 || TestMonth == 11)&& TestDay == 30)
740
    {
741
    TomorrowDay = 1;
742
    TomorrowMonth = TestMonth +1 ;
743
    TomorrowYear = TestYear;
744
    }
745
  else if ((TestMonth == 1 || TestMonth == 3 || TestMonth == 5 || TestMonth == 7 || TestMonth == 8 || TestMonth == 10)&& TestDay == 31)
746
    {
747
    TomorrowDay = 1;
748
    TomorrowMonth = TestMonth +1 ;
749
    TomorrowYear = TestYear;
750
    }
751
  else 
752
    {
753
      TomorrowDay = TestDay + 1;
754
      TomorrowMonth = TestMonth;
755
      TomorrowYear = TestYear;
756
    }
757
  NextDays[i] = TomorrowDay;
758
  NextMonths[i] = TomorrowMonth;
759
  NextYears[i] = TomorrowYear;
760
  TestDay = TomorrowDay;
761
  TestMonth = TomorrowMonth;
762
  TestYear = TomorrowYear;
763
 
764
  }
765
 
766
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy This Password *

* Type Or Paste Password Here *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


Hit Counter provided by orange county property management