Good evening AWOL
You are right! Please, sorry.
Thanks to your tip, I've found that the problem is when my string is < 10, because I concatenate "0" + sSS string.
If my sSS string is equal or bigger than 10, I don't have that problem and function 'concatena5' works great.
The problem is found... I don't know how to fix it, or avoid...
int intHora;
int intMinutos;
int intSegundos;
char * sHH;
char * sMM;
char * sSS;
const int nHoras=2;
const int nMinutos=1;
const int nSegundos=0;
char Debug[40];
char* cstr(int Parametro){
itoa(Parametro,Debug,10);
return strdup(Debug);
}
char *concatena(char *string1, char *string2) {
StringFinal[0]='\0';
strcat(StringFinal, string1);
strcat (StringFinal, string2);
return StringFinal;
}
char *concatena5(char *string1, char *string2, char *string3, char *string4, char *string5) {
strcpy(StringFinal, string1);
strcat(StringFinal, string2);
strcat(StringFinal, string3);
strcat(StringFinal, string4);
strcat(StringFinal, string5);
return(StringFinal);
}
int LeEEPROM(int ID){
return (EEPROM.read(ID));
}
void GravaEEPROM(int ID, int Valor){
EEPROM.write(ID,Valor);
}
void Escreve_LCD2(char *sTexto){
lcd.cursorTo(2,1);
lcd.printIn(sTexto);
}
void loop() {
GravaEEPROM(nHoras,10);
intHora=LeEEPROM(nHoras);
sHH=cstr(intHora);
if (intHora<10){ sHH=concatena("0",sHH);
}
GravaEEPROM(nMinutos,10);
intMinutos=LeEEPROM(nMinutos);
sMM=cstr(intMinutos);
if (intMinutos<10){
sMM=concatena("0",sMM);
}
GravaEEPROM(nSegundos,1);
intSegundos=LeEEPROM(nSegundos);
sSS=cstr(intSegundos);
if (intSegundos<10){ sSS=concatena("0",sSS);
}
Escreve_LCD2(concatena5(sHH,":",sMM,":",sSS));
delay(5000);
}
I'll appreciate your prompt help
Thanks on advance
Pedro Ferrer