We need to see you full code...
For example - If you don't initialize myYear anywhere then it should be no surprise that values are zero for a global variable.
I like to make use of the "extra" time functions in the AVR-libc library (not contained in TimeLib.h)
as described in: https://www.arduino.cc/en/Tutorial/UsingAVRlibraries
excerpt: "Because Arduino already links It links against AVR Libc (the AVR libraries),
it is easy to use them. To use a libc library only the header needs to be included..."
for instance I like to use the function "sun_rise (const time_t *timer)"
(obtaining a ntp timestamp already solved)
for a list of time.h lib's see: avr-libc: Modules darin u.A. <time.h>
you will find the modules for calculating time of sunrise at a spcific location:
sun_rise (const time_t *timer), time_t
sun_set (const time_t *timer)
set_zone (int32_t)
set_position (int32_t latitude int32_t longitude) etc
What a stone age man know how to do (-> Stonehenge) I can't without help from arduino community.
So I'm asking for an simple AVR-libc time.h example.
As a newbee I'm not so familar useing / decoding the doxygen documentation
nor are the examples helpfull to me
thank you J-M-L for jumping in. As a non native speaker GoForSmokes answer "...Arduino is not a watch company" makes no sense to me nor seems it related to my question.
I've already mentioned that I receive and process NTP time stamps (primarily from german time server at ptb). No problem with receiving time/date strings delivered by an DCF77 receiver, more over I own a gps receiver from which I get time and geographical data. No problem by adding a DS1307 RTC however how is this related to my question???
All I asked for was "...how to use and set the pointer in time_t time ( time_t * timer) " module/function/methode you name it.
It's up to you GoForSmoke or any other Arduino community member to answer this (simple and maybe silly newbie) question. Either status nor karma rate counts, it should just be a working solution.
Arduino clock is not so perfect. RTC is Real Time Clock, one way people use for being sure of the time.
Your way is good too but I think cost more over time.
MHz:
I've already mentioned that I receive and process NTP time stamps (primarily from german time server at ptb). No problem with receiving time/date strings delivered by an DCF77 receiver, more over I own a gps receiver from which I get time and geographical data. No problem by adding a DS1307 RTC however how is this related to my question???
All I asked for was "...how to use and set the pointer in time_t time ( time_t * timer) " module/function/methode you name it.
I think there is a confusion on what to do to get what you want to achieve.
if you want to use the standard library, then because "Arduino is not a watch" and thus it does not know what time it is, you need to first initialize the time in your arduino.
Once this is done, time functions from the Arduino Time library are available
so
time_t t = now(); // Store the current time in time variable t
then your pointer is just &t
It might be confusing why we need to pass a pointer to the time_t value, I would guess that in the early days of computing the time() function could not directly return a long int and thus the data was passed by reference...
J-M-L:
It might be confusing why we need to pass a pointer to the time_t value, I would guess that in the early days of computing the time() function could not directly return a long int and thus the data was passed by reference...
There were no long ints, so it was hidden as a struct. Same reason for size_t.