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.
Revision 0:9f741d395d17, committed 2014-08-07
- Comitter:
- eencae
- Date:
- Thu Aug 07 13:13:02 2014 +0000
- Commit message:
- Initial commit.; ; Reads Unix time as a string over serial and uses it to update the time on the RTC.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 9f741d395d17 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Aug 07 13:13:02 2014 +0000 @@ -0,0 +1,49 @@ +#include "mbed.h" + +Serial serial(USBTX,USBRX); + +void serialISR(); // ISR that is called when serial data is received +void setTime(); // function to set the UNIX time +int setTimeFlag = 0; // flag for ISR + +char rxString[16]; // buffer to store received string + +int main() +{ + serial.attach(&serialISR); // attach serial ISR + char buffer[30]; // buffer used to store time string + + set_time(0); // initialise time to 1st January 1970 + + while(1) { + + time_t seconds = time(NULL); // get current time + // format time into a string (time and date) + strftime(buffer, 30 , "%X %D", localtime(&seconds)); + // print over serial + serial.printf("Time = %s\n",buffer); + wait(1.0); // delay for a second + + if (setTimeFlag) { // if updated time has been sent + setTimeFlag = 0; // clear flag + setTime(); // update time + } + } + +} + +void setTime() { + // print time for debugging + serial.printf("set_time - %s",rxString); + // atoi() converts a string to an integer + int time = atoi(rxString); + // update the time + set_time(time); +} + +void serialISR() { + // when a serial interrupt occurs, read rx string into buffer + serial.gets(rxString,16); + // set flag + setTimeFlag = 1; +}
diff -r 000000000000 -r 9f741d395d17 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Aug 07 13:13:02 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/6213f644d804 \ No newline at end of file