I am trying to get the time using the time.h library. But i don't understand how it works?
Does the Time.h library get the time from the computer? Or is there a counter in time.h and then it calculates the time and tells us?
I asked it, because now i can get the time correctly(Arduino connected to my computer). But if i don't use a computer after uploading the code to Arduino, can't i get the time using the Time.h library?
I am trying to get the time using the time.h library.
From what? The Arduino does NOT know what time it is. The time.h library knows how to sync the time/date, using some function that YOU write, that knows how to get the time/date from an RTC, from a PC, from an NTP source, etc.
Does the Time.h library get the time from the computer?
Not unless the function that you write gets the time from some computer.
Or is there a counter in time.h and then it calculates the time and tells us?
Once the time library gets the time and date, from the function YOU write, it uses millis() to know how much time has elapsed, and updates its concept of now with that information, until it is time to sync again.
But if i don't use a computer after uploading the code to Arduino, can't i get the time using the Time.h library?
There is NOTHING magic about what the time library does. If your function, called when the library needs to sync, can get the time, then the time library can tell you the time/date. If your function tries to get the time from the PC, and the PC is not connected, then the time library will have garbage to keep current.
PaulS:
From what? The Arduino does NOT know what time it is. The time.h library knows how to sync the time/date, using some function that YOU write, that knows how to get the time/date from an RTC, from a PC, from an NTP source, etc.
Not unless the function that you write gets the time from some computer.
Once the time library gets the time and date, from the function YOU write, it uses millis() to know how much time has elapsed, and updates its concept of now with that information, until it is time to sync again.
There is NOTHING magic about what the time library does. If your function, called when the library needs to sync, can get the time, then the time library can tell you the time/date. If your function tries to get the time from the PC, and the PC is not connected, then the time library will have garbage to keep current.
Thank you very much for explaining the subject in detail.