tmElements

sir/maam: how to fix this "tmElements_t was not declared in this scope" what is the problem of this?? thank you

I can see nothing wrong with the code that you have not posted.

Please read this before posting a programming question

The problem is that tmElements was not declared in the scope in which it was used.

See hsnippets-r-us.com

this is the code:

#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>

const char *monthName[12] = {
“Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”,
“Jul”, “Aug”, “Sep”, “Oct”, “Nov”, “Dec”
};

tmElements_t tm;

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™) {
config = true;
}
}

Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor
delay(200);
if (parse && config) {
Serial.print(“DS1307 configured Time=”);
Serial.print(TIME);
Serial.print(", Date=");
Serial.println(DATE);
} else if (parse) {
Serial.println(“DS1307 Communication Error :-{”);
Serial.println(“Please check your circuitry”);
} else {
Serial.print(“Could not parse info from the compiler, Time=”");
Serial.print(TIME);
Serial.print("", Date="");
Serial.print(DATE);
Serial.println(""");
}
}

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 = Hour;
tm.Minute = Min;
tm.Second = Sec;
return true;
}

bool getDate(const char *str)
{
char Month[12];
int Day, Year;
uint8_t monthIndex;

if (sscanf(str, “%s %d %d”, Month, &Day, &Year) != 3) return false;
for (monthIndex = 0; monthIndex < 12; monthIndex++) {
if (strcmp(Month, monthName[monthIndex]) == 0) break;
}
if (monthIndex >= 12) return false;
tm.Day = Day;
tm.Month = monthIndex + 1;
tm.Year = CalendarYrToTm(Year);
return true;
}

when i trying to upload this on my arduino uno with also a rtc module the said error has been pop up.

"tmElements_t was not declared in this scope"

Is that the full text of the error message ?

tmElements_t is a structure declared in TimeLib.h

You need to have the Time-Master folder in your libraries path and then include both the Time and TimeLib headers, in your sketch.

#include <Time.h>
#include <TimeLib.h>

tmElements_t tmNow;

//...
#include <Time.h>

tmElements_t tmNow;#]

Works for me

MattS-UK: You need to have the Time-Master folder in your libraries path and then include both the Time and TimeLib headers, in your sketch.

It's good form to rename xxx-Master to xxx, where xxx is the name of the library. I keep all my master libraries in another folder for future use and to keep them clean in case I modify something in a library.

You don't have to include TimeLib.h.