Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SX1276Lib AdaFruit_RGBLCD MCP23017 mbed
Fork of AdaFruit_RGBLCD by
datetime.cpp
- Committer:
- ftagius
- Date:
- 2015-07-29
- Revision:
- 32:a2472bbe7c92
File content as of revision 32:a2472bbe7c92:
#include "datetime.h"
#include "rtc_api.h"
#include "mbed.h"
void SetDateTime
(int year = 2015
,int mon = 5
,int day = 26
,int hour = 10
,int min = 0
,int sec = 0
)
{
// struct tm Clock;
Clock.tm_year = year - 1900;
Clock.tm_mon = mon;
Clock.tm_mday = day;
Clock.tm_hour = hour;
Clock.tm_min = min;
Clock.tm_sec = sec;
time_t epoch = mktime(&Clock);
if (epoch == (time_t) -1) {
error("Error in clock setting\r\n");
}
set_time(epoch);
}
void ShowDateTime()
{
char str[32];
time_t seconds = time(NULL);
struct tm *gpsd = localtime(&seconds);
struct tm *tminfo = localtime(&seconds);
strftime(str, 32, "%F,%T", tminfo);
//printf("RTC: %s\r\n", str);
printf("%02d/%02d/%02d,", gpsd->tm_mon, gpsd->tm_mday, gpsd->tm_year+1900);
printf("%02d:%02d:%02d ", gpsd->tm_hour, gpsd->tm_min, gpsd->tm_sec);
}
