ผมได้อัปโหลดโค๊ดดังนี้
#include
#include
#include
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(tm)) {
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;
}
เพื่อตั้งเวลาสำหรับบันทึกข้อมูลลง SD Card แต่ไม่สำเร็จและมีข้อความแสดงขึ้นดังนี้
Arduino: 1.8.12 (Windows 10), Board: "Arduino Uno"
In file included from C:\Users\Y520\AppData\Local\Temp\arduino_modified_sketch_299543\SetTime.ino:1:0:
C:\Users\Y520\Documents\Arduino\libraries\DS1307RTC/DS1307RTC.h:19:22: error: 'tmElements_t' has not been declared
static bool read(tmElements_t &tm);
^~~~~~~~~~~~
C:\Users\Y520\Documents\Arduino\libraries\DS1307RTC/DS1307RTC.h:20:23: error: 'tmElements_t' has not been declared
static bool write(tmElements_t &tm);
^~~~~~~~~~~~
C:\Users\Y520\AppData\Local\Temp\arduino_modified_sketch_299543\SetTime.ino: In function 'void setup()':
SetTime:20:21: error: no matching function for call to 'DS1307RTC::write(tmElements_t&)'
if (RTC.write(tm)) {
^
In file included from C:\Users\Y520\AppData\Local\Temp\arduino_modified_sketch_299543\SetTime.ino:1:0:
C:\Users\Y520\Documents\Arduino\libraries\DS1307RTC/DS1307RTC.h:20:17: note: candidate: static bool DS1307RTC::write(int&)
static bool write(tmElements_t &tm);
^~~~~
C:\Users\Y520\Documents\Arduino\libraries\DS1307RTC/DS1307RTC.h:20:17: note: no known conversion for argument 1 from 'tmElements_t' to 'int&'
exit status 1
no matching function for call to 'DS1307RTC::write(tmElements_t&)'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
ผมต้องแก้ไขตรงไหนครับ
ในนี้แจ้งว่าไม่มีไฟล์ไลบารี ลองเช็คไลบารีหรือใช้ไลบารีตัวใหม่ครับ
C:\Users\Y520\Documents\Arduino\libraries\DS1307RTC\DS1307RTC.h:19:22: error: 'tmElements_t' has not been declared
static bool read(tmElements_t &tm);
ในนี้แจ้งว่าไลบารีไม่ถูกต้องครับ
ตัวอย่างดังนี้ครับ https://www.allnewstep.com/p/3661