Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
7148_Labs_2223/Session5/RTC/src/main.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
42 lines (32 sloc)
1.02 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <mbed.h> | |
#include "Rtc_Ds1307.h" | |
Rtc_Ds1307 rtc(I2C_SDA, I2C_SCL); | |
int main() { | |
printf("\n[Build] %s %s\n", __DATE__, __TIME__); | |
DigitalOut led(LED1); | |
// put your setup code here, to run once: | |
time_t localTime; | |
Rtc_Ds1307::Time_rtc rtcTime; | |
rtcTime.year=2023; | |
rtcTime.date=23; | |
rtcTime.mon=3; | |
rtcTime.hour=12; | |
rtcTime.min=30; | |
rtcTime.sec = 12; | |
rtc.setTime(rtcTime, true, false); | |
//getTime(); | |
while(1) { | |
// put your main code here, to run repeatedly: | |
//Get the Local Time | |
localTime = time(NULL); | |
printf("Time as seconds since January 1, 1970 = %u\n", (unsigned int)localTime); | |
printf("Time as a basic string = %s\n", ctime(&localTime)); | |
rtc.getTime(rtcTime); | |
printf("%d:%d:%d Year %d\n", rtcTime.hour, rtcTime.min, rtcTime.sec, rtcTime.year); | |
//printf("RTC as seconds since January 1, 1970 = %u\n", (unsigned int)rtcTime); | |
//printf("RTC as a basic string = %s\n", ctime(&rtcTime)); | |
//getTime(); | |
led = !led; | |
thread_sleep_for(10000); | |
} | |
} |