Had the same idea a few weeks ago. You can try this and see if it fits what you want. It counts sec, min, hrs & days. Depending on your
"clock" time you may have to adjust a few ms in the delays. The way it's setup is working perfect for me.
/* This sketch is basically a clock function even though it doesn't
"tell" time. I designed it to perform operations at a certain time
of the day. Depending on what time you start the program, you would
have to adjust the time of the operation accordingly. (unless you want
to start the program at midnight) I start by (Scount) counting milli-
seconds, then (Mcount) minutes etc.... It prints to the LCD (4 x 20)
sec, min, hrs, days.
garym
*/
#include <LiquidCrystal.h> // lib. for LCD
int Scount = 0; // count seconds
int Mcount = 0; // count minutes
int Hcount =0; // count hours
int Dcount = 0; // count days
LiquidCrystal lcd(7,8,9,10,11,12); // pins connected to LCD
void setup()
{
lcd.begin(20,4); // open the LCD
}
void loop()
{
lcd.setCursor(0,2); // sets cursor to 3rd line
lcd.print ("Hour ");
lcd.print (Hcount);
lcd.print (" ");
lcd.setCursor (0,3); // sets cursor to 4th line
lcd.print ("DAY ");
lcd.print (Dcount);
if ( Mcount == 60) // if Mcount is 60 do this operation
{
delay (32); // good place to fine tune timing
Mcount = 0; // reset Mcount
Hcount ++;
}
if (Hcount> 23)
{
Dcount++;
Hcount = 0; // have to reset Hcount to "0" after 24hrs
}
lcd.setCursor (0,1); // sets cursor to 2nd line
lcd.print (Mcount);
lcd.print (" min ");
lcd.setCursor (0,0); // sets cursor to 1st line
lcd.print (Scount);
lcd.print (" SEC ");
if (Scount >59) // if 60 do this operation
{
Mcount ++; // add 1 to Mcount
Scount = 0; // reset Scount
delay (58); // changes ms per min
}
if (Scount < 60) // do this oper. 59 times
// to count the seconds
{
delay (988); // changing by one = 60 ms a min
Scount ++; // add 1 to Scount
}
}