assuming you have timeinfo properly setup, the structure looks like this (give or take)
struct tm {
int tm_sec; /* seconds after the minute [0-60] */
int tm_min; /* minutes after the hour [0-59] */
int tm_hour; /* hours since midnight [0-23] */
int tm_mday; /* day of the month [1-31] */
int tm_mon; /* months since January [0-11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday [0-6] */
int tm_yday; /* days since January 1 [0-365] */
int tm_isdst; /* Daylight Saving Time flag */
long tm_gmtoff; /* offset from UTC in seconds */
char *tm_zone; /* timezone abbreviation */
};
So if timeinfo is the instance of the struct and is a global variable, then you would do
Indeed. If you want to share data between functions, you must either make it a global variable, or pass it as a parameter from one function to the other.
Two functions with local variables, which happen to have the same name, is not sharing data,
This is beginner level stuff. What is your level of experience?
I was not able to use inline int function, cause this function is trigged elsewhere in the code.
I managed to resolve the problem partially by using global struct tm timeinfo.
My code looks like this:
void timeupdate() {
int hours = timeinfo.tm_hour ;
int minutes = timeinfo.tm_min ;
Serial.println("You have just updated time from NTP!");
Serial.println(hours); // print an updated time
Serial.println(minutes); // print an updated time
}
However, the integers hours and minutes are global integers with values defined at the start of the code. After that their values increase with microcontroller time.
Problem is, updating the values of hours and minutes by my function timeupdate() does not result in changing the current value of hours and minutes.
Serial monitor shows the updated values, but on 7 segment display they do not change.
I have used also SimpleTime example and few others, I think my problem is related not to this particular library but the knowledge how the microcontroller processes information.
I have resolved my problem partially by defining a global struct tm timeinfo, just now I try to update initial values of integers by new values, obtained by my function timeupdate - and it seems to be not so obvious.
You are creating hours and minutes as local variables inside the timeupdate() funtion. The global hours and minutes variables will be unaffected by any data stored in the local variables. Remove the "int" before hours and minutes to use the global variables in the function.