Hello Mitch,
Im not sure if I got it.
And to be more clear:
The code:
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>
int minute = 0;
int hour = 0;
int hourT;
int minuteT;
int secondT;
int dayT;
int monthT;
int yearT;
char hourS[5];
char minuteS[5];
char secondS[5];
char allhour[60];
char te[4] ;
void setup()
{
Serial.begin(9600);
}
void loop() {
char allhour[60] = "" ; //// DECLARATION IS HERE ////
hourT = (RTC.get(DS1307_HR,true)) ;
minuteT = (RTC.get(DS1307_MIN,false)) ;
secondT = (RTC.get(DS1307_SEC,false));
dayT = (RTC.get(DS1307_DATE,false));
monthT = (RTC.get(DS1307_MTH,false));
yearT = (RTC.get(DS1307_YR,false));
itoa(hourT, hourS, 10);
itoa(minuteT, minuteS, 10);
itoa(secondT, secondS, 10);
if (strlen(hourS) < 2) { char te[4] = "0" ; strcat(te, hourS); strcpy (hourS, te); }
if (strlen(minuteS) < 2) { char te[4] = "0" ; strcat(te, minuteS); strcpy (minuteS, te); }
if (strlen(secondS) < 2) { char te[4] = "0" ; strcat(te, secondS); strcpy (secondS, te); }
strcat(allhour, hourS) ;
strcat(allhour, "/");
strcat(allhour, minuteS);
strcat(allhour, "/");
strcat(allhour, secondS);
Serial.println(allhour);
delay(1000);
}
Works as desired, returning values like:
02/06/36
02/06/37
02/06/38
02/06/39
02/06/40
02/06/41
02/06/42
And the code:
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>
int minute = 0;
int hour = 0;
int hourT;
int minuteT;
int secondT;
int dayT;
int monthT;
int yearT;
char hourS[5];
char minuteS[5];
char secondS[5];
char allhour[60];
char te[4] ;
void setup()
{
Serial.begin(9600);
}
void loop() {
hourT = (RTC.get(DS1307_HR,true)) ;
minuteT = (RTC.get(DS1307_MIN,false)) ;
secondT = (RTC.get(DS1307_SEC,false));
dayT = (RTC.get(DS1307_DATE,false));
monthT = (RTC.get(DS1307_MTH,false));
yearT = (RTC.get(DS1307_YR,false));
itoa(hourT, hourS, 10);
itoa(minuteT, minuteS, 10);
itoa(secondT, secondS, 10);
if (strlen(hourS) < 2) { char te[4] = "0" ; strcat(te, hourS); strcpy (hourS, te); }
if (strlen(minuteS) < 2) { char te[4] = "0" ; strcat(te, minuteS); strcpy (minuteS, te); }
if (strlen(secondS) < 2) { char te[4] = "0" ; strcat(te, secondS); strcpy (secondS, te); }
strcat(allhour, hourS) ;
strcat(allhour, "/");
strcat(allhour, minuteS);
strcat(allhour, "/");
strcat(allhour, secondS);
Serial.println(allhour);
delay(1000);
char allhour[60] = "" ; //// DECLARATION IS NOW HERE ////
}
Dont work as desired as:
02/03/36
02/03/3602/03/37
02/03/3602/03/3702/03/38
02/03/3602/03/3702/03/3802/03/39
02/03/3602/03/3702/03/3802/03/3902/03/40
02/03/3602/03/3702/03/3802/03/3902/03/4002/03/42
02/03/3602/03/3702/03/3802/03/3902/03/4002/03/4202/03/43
02/03/3602/03/3702/03/3802/03/3902/03/4002/03/4202/03/4302/0n/44A
Point is that in both cases the char type is declared twice, as you said, but in one case it works but dont for the second case. See that the only difference between the two codes is that in the first code, 'char allhour[60] = "" ; ' is the first command of void loop() and in the second code, 'char allhour[60] = "" ; ' is the last command of void loop().
The logic says to me that if a command is explicit as the very first of void loop() or if explicit as latest one, cant alter your final result. Considering that void loop() keeps cycling until you turn Arduino off or reset.
The only thing i can imagine is that after loop sequence restart, something change, some buffer is cleared or anything else that i really dont know. Or even: Im just too stupid to state what´s going on 