johnny78
Full Member level 5
- Joined
- Jun 28, 2017
- Messages
- 270
- Helped
- 1
- Reputation
- 2
- Reaction score
- 5
- Trophy points
- 1,298
- Activity points
- 3,469
void setup() {
bool parse=false;
bool config=false;
// get the date and time the compiler was run
if (getDate(__DATE__) && getTime(__TIME__)) {
parse = true;
// and configure the RTC with this info
if (RTC.write(tm)) {
config = true;
}
}
would you please help me to understand this code?I think you should look at what the "tm" means as a parameter in "RTC.write(tm)".
It is a structure containing each element of the time and date. You have to fill the elements yourself with your own numbers then call the function. The getTime and getDate do just that, inserting the current date and time into the structure.
For example "tm_hour = 12;" would take a value between 0 and 23 and set the hour entry in the structure to 12 (mid day). If you then used "RTC.write(tm);" it would set the DS1307 hour to 12. Obviously, fill in the other parts of the tm structure first as they will also be written into the DS1307.
Brian.
tmElements_t tm;
void setup() {
bool parse = false;
bool config = false;
// get the date and time the compiler was run
if (getTime(__TIME__)) {
parse = true;
// and configure the RTC with this info
if (RTC.write(tm)) {
config = true;
}
}
}
void loop() {
}
bool getTime(const char *str)
{
int Hour, Min, Sec;
if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false;
tm.Hour = (12); // originally (12) was Hour
tm.Minute = (25);// originally (25) was Minute
return true;
}
thanks KlausHi,
manually? What does that mean?
* two pushbuttons controlling SCL and SDA?
* 4 buttons using microcontroller for UP, DOWN, ENTER, MENU
* using a rotary encoder
* using a touch screen
* ???
* do you have a display? If yes, which one and how is it controlled?
What help do you need?
* doing internet search for you
* help with hardware
* help with writing code
* ???
I guess you need to explain.
Klaus
unfortunately noThe confusing point is that you give the impression of understanding how the regular set time example works. Presume it uses the same RTC.write() functions?
Code:
tmElements_t tm;
void setup() {
bool parse = false; // not sure what this does - used elsewhere in the program
bool config = false; // not sure what this does - used elsewhere in the program
// get the date and time the compiler was run
if (getTime(__TIME__)) { // __TIME__ is a complier variable that holds the present computer time
parse = true;
// and configure the RTC with this info
if (RTC.write(tm)) { // this writes the compiler time into the RTC
config = true;
}
}
}
void loop() {
}
bool getTime(const char *str)
{
int Hour, Min, Sec; // these are local variables to hold the time numbers
if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false; // reads the string 'str' passed to the function and extracts values from it
tm.Hour = (12); // originally (12) was Hour // would have loaded the Hour from the line above.
tm.Minute = (25);// originally (25) was Minute // would have loaded the Minute from two lines above.
return true; // returns 'OK', if the wrong number of parameters had been passed in 'str', false would already have been returned.
}
hiCode:Code: tmElements_t tm; void setup() { bool parse = false; // not sure what this does - used elsewhere in the program bool config = false; // not sure what this does - used elsewhere in the program // get the date and time the compiler was run if (getTime(__TIME__)) { // __TIME__ is a complier variable that holds the present computer time parse = true; // and configure the RTC with this info if (RTC.write(tm)) { // this writes the compiler time into the RTC config = true; } } } void loop() { } bool getTime(const char *str) { int Hour, Min, Sec; // these are local variables to hold the time numbers if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false; // reads the string 'str' passed to the function and extracts values from it tm.Hour = (12); // originally (12) was Hour // would have loaded the Hour from the line above. tm.Minute = (25);// originally (25) was Minute // would have loaded the Minute from two lines above. return true; // returns 'OK', if the wrong number of parameters had been passed in 'str', false would already have been returned. }
if (getTime(__TIME__)) {
parse = true;
bool getTime(const char *str);
bool parse = false;
bool config = false;
if (getTime(__TIME__)) {
parse = true;
// and configure the RTC with this info
if (RTC.write(tm)) {
config = true;
}
}
Are you asking about a recent post of yours? No post was deleted in this thread. If you are missing a post, it got possibly lost due to server issues. This happens very rarely but can happen.why i cant see the latest post ?
sorry but in this thread last time i checked it Mr betwixt has replied in my post but i couldnt read itAre you asking about a recent post of yours? No post was deleted in this thread. If you are missing a post, it got possibly lost due to server issues. This happens very rarely but can happen.
As KlausST mentioned, please give more info, or simply repost.
ok Mr im sorry but as i guess i posted in the same thread asking for lost postHi,
you should be nominated for the award for asking the most unelaborated questions.
Think about this:
* you see some posts
* we see some posts
* we see only "our" posts, so we don´t kow what you see.
For sure we all do see "some latest post". No one knows whether we see the same "latest post".
Thus I guess it should be a good idea to tell
* which "latest post you see" and
* which post you miss
******
What´s the highest number you can think of? Then add 1 to it.
Klaus
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?