It's really a straight copy/paste with the two corrections that I noted but here you go:
/*
Code under (cc) by Manuel Gonzalez, www.codingcolor.com
http://creativecommons.org/license/cc-gpl
Pins 12, 11, 5, 4, 3, 2 to LCD
Analog pins 4 (SDA),5(SCL) to Chronodot
Pins 6 (hour), 7(min) buttons
*/
#include <Wire.h>
#include <LiquidCrystal.h>
const int hourButtonPin = 6;
const int minButtonPin = 7;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int hourButtonState;
int minButtonState;
int seconds; //00-59;
int minutes; //00-59;
int hours;//1-12 - 00-23;
int day;//1-7
int date;//01-31
int month;//01-12
int year;//0-99;
void setup()
{
pinMode(hourButtonPin,INPUT);
pinMode(minButtonPin,INPUT);
Wire.begin();
lcd.begin(16, 2);
hourButtonState = 0;
minButtonState = 0;
////////////////////////////////
seconds = 00;
minutes = 26;
hours = 17;
day = 7;
date = 31;
month = 5;
year = 10;
//initChrono();//just set the time once on your RTC
///////////////////////////////
}
void loop()
{
check_buttons();
get_time();
get_date();
display_time();
display_date();
delay(1000);
}
void display_time()
{
char buf[12];
lcd.setCursor(0, 0);
if(hours == 0)
{
lcd.clear();
}
lcd.print("Time ");
lcd.print(itoa(hours, buf, 10));
lcd.print(":");
if(minutes < 10)
{
lcd.print("0");
}
lcd.print(itoa(minutes, buf, 10));
lcd.print(":");
if(seconds < 10){
lcd.print("0");
}
lcd.print(itoa(seconds, buf, 10));
}
void display_date()
{
char buf[12];
lcd.setCursor(0, 1);
lcd.print("Date ");
if(month < 10){
lcd.print("0");
}
lcd.print(itoa(month, buf, 10));
lcd.print("/");
lcd.print(itoa(date, buf, 10));
lcd.print("/");
if(year < 10){
lcd.print("0");
}
lcd.print(itoa(year, buf, 10));
}
void initChrono()
{
set_time();
set_date();
}
void set_date()
{
Wire.beginTransmission(104);
Wire.write(3);
Wire.write(decToBcd(day));
Wire.write(decToBcd(date));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.endTransmission();
}
void get_date()
{
Wire.beginTransmission(104);
Wire.write(3);//set register to 3 (day)
Wire.endTransmission();
Wire.requestFrom(104, 4); //get 5 bytes(day,date,month,year,control);
day = bcdToDec(Wire.read());
date = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}
void set_time()
{
Wire.beginTransmission(104);
Wire.write(0);
Wire.write(decToBcd(seconds));
Wire.write(decToBcd(minutes));
Wire.write(decToBcd(hours));
Wire.endTransmission();
}
void get_time()
{
Wire.beginTransmission(104);
Wire.write(0);//set register to 0
Wire.endTransmission();
Wire.requestFrom(104, 3);//get 3 bytes (seconds,minutes,hours);
seconds = bcdToDec(Wire.read() & 0x7f);
minutes = bcdToDec(Wire.read());
hours = bcdToDec(Wire.read() & 0x3f);
}
void setHour()
{
hours++;
if(hours > 23)
{
hours = 0;
seconds = 0;
minutes = 0;
}
set_time();
}
void setMinutes()
{
minutes++;
if(minutes > 59)
{
minutes = 0;
}
seconds=0;
set_time();
}
void check_buttons()
{
hourButtonState = digitalRead(hourButtonPin);
minButtonState = digitalRead(minButtonPin);
if(hourButtonState == HIGH){
setHour();
}
if(minButtonState == HIGH){
setMinutes();
}
}
///////////////////////////////////////////////////////////////////////
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
//////////////////////////////////////////////////////////////////////