Hi all,
My Arduino watch doesn't continue working when I unplug it from the power. It has a full charged button battery but it only keeps the last time.
Perhap I need to add something else to the code that I'm forgetting?
I'm using these function to get and set the time;
void getDate(byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayOfMonth, byte *month, byte *year)
{
Date[0] = '\0';
char aux[3];
aux[0] = '\0';
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive() & 0x7f);
*hour = bcdToDec(Wire.receive());
*dayOfWeek = bcdToDec(Wire.receive() & 0x3f);
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
if(*hour < 10)
strcat(Date, "0");
itoa(*hour,aux,10);
strcat(Date,aux);
strcat(Date, ":");
if(*minute < 10)
strcat(Date, "0");
itoa(*minute,aux,10);
strcat(Date,aux);
strcat(Date, ":");
if(*second < 10)
strcat(Date, "0");
itoa(*second,aux,10);
strcat(Date,aux);
strcat(Date, " ");
switch (*dayOfWeek) //dayOfWeek
{
case 1:
//strcat(STRdayOfWeek,"Lu");
strcat(Date, "Lu");
break;
case 2:
//strcat(STRdayOfWeek,"Ma");
strcat(Date, "Ma");
break;
case 3:
//strcat(STRdayOfWeek,"Mi");
strcat(Date, "Mi");
break;
case 4:
//strcat(STRdayOfWeek,"Ju");
strcat(Date, "Ju");
break;
case 5:
//strcat(STRdayOfWeek,"Vi");
strcat(Date, "Vi");
break;
case 6:
//strcat(STRdayOfWeek,"Sa");
strcat(Date, "Sa");
break;
case 7:
//strcat(STRdayOfWeek,"Do");
strcat(Date, "Do");
break;
}
strcat(Date, " ");
if(*dayOfMonth < 10)
strcat(Date, "0");
itoa(*dayOfMonth,aux,10);
strcat(Date,aux);
strcat(Date, "/");
if(*month < 10)
strcat(Date, "0");
itoa(*month,aux,10);
strcat(Date,aux);
strcat(Date, "/");
if(*year < 10)
strcat(Date, "0");
itoa(*year,aux,10);
strcat(Date,aux);
//lcd.print(Date);
}
//Configurar fecha y hora del reloj
void setDate(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second));
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour));
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.endTransmission();
}
Regards