Hi,
can I ask you a c-beginners question?
I have problems with my time structure. This is basicly my code:
void function_1();
void function_2();
struct tm *tmp;
char LCDTime[20];
void setup() {
...setup stuff
}
void loop() {
function_1();
function_2();
delay (1000);
}
void function_1(){
time_t now = time(nullptr);
tm *tmp = localtime(&now);
sprintf (LCDTime, "%02d:%02d:%02d", tmp->tm_hour , tmp->tm_min, tmp->tm_sec);
DEBUG.println (tmp->tm_sec);
}
void function_2(){
DEBUG.println (LCDTime);
DEBUG.println (tmp->tm_sec); // <---------------------- causing wdt reset!!!!!!
}
problem is the line " DEBUG.println (tmp->tm_sec); " In function_1() its working w/o problem
How can I use the elements of the structure tmp in function_2()?
tm *tmp = localtime(&now);
in function_1()
time_t now
global
time_t now = time(nullptr);
inside f1 is variable allocation and scope only inside that function
tm *tmp = localtime(&now)
is a function, that allocates the actual time to the struct...tm *tmp = localtime(&now)
remove from function_1struct tm *tmp = localtime(&now)
as global declaration for line 3?struct tm *tmp
as global declaration for line 3?tmp = localtime(&now)
; in fc1()struct tm tmp
as a global var
*tmp = localtime(&now);
in fc1()? Sorry I can only guess....