This sketch demonstrates how add and substract time values using the time span objects
Dependencies: Hotboards_rtcc mbed
Revision 0:5e1b09cde0a8, committed 2016-02-10
- Comitter:
- Hotboards
- Date:
- Wed Feb 10 15:49:52 2016 +0000
- Commit message:
- first release
Changed in this revision
diff -r 000000000000 -r 5e1b09cde0a8 Hotboards_rtcc.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hotboards_rtcc.lib Wed Feb 10 15:49:52 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/Hotboards/code/Hotboards_rtcc/#0790bcaf8b8f
diff -r 000000000000 -r 5e1b09cde0a8 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Feb 10 15:49:52 2016 +0000 @@ -0,0 +1,76 @@ +/* + Hotboards_rtcc Library - setting time and date + Demonstrates the use a MCP7941x clock calendar. The Hotboards_rtcc + + library works with this microchip real time clock + (http://www.hotboards.org). + + This sketch demonstrates how add and substract time values using + the time span objects + + The circuit: + * VDD --> 3.3v + * GND --> GND + * SDA --> SDA + * SCL --> SCL +*/ +#include "mbed.h" +#include "Hotboards_rtcc.h" + +/* days of the week */ +const char *week[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; +/* months of the year */ +const char *months[] = {"JAN","FEB","MAR","APR","MAY","JUN", "JUL", "AUG","SEPT","OCT","NOV","DEC"}; + +/*serial port init*/ +Serial pc(USBTX,USBRX); +/*i2c instance delaration for use with the rtcc library*/ +I2C device(PB_9, PB_8); +/*lets declare and rtcc instance */ +Hotboards_rtcc rtcc(device); + +/*function for display date time */ +void display_DateTime( DateTime &dt ) +{ + printf( " Time- %d:%d:%d Date- %s/%d/%s/%d \n",dt.hour( ),dt.minute( ),dt.second( ),week[dt.dayOfTheWeek( )],dt.day( ),months[dt.month( )],dt.year()); +} + + +int main() +{ + /*i2c bus clock set to 100khz*/ + device.frequency(100000); + /* init the rtcc, just enable the clock if not already enable */ + rtcc.begin(); + /* set the time (15:30:00) and date 1/MAR/2001 */ + rtcc.adjust( DateTime( 2001, 2, 1, 15, 30, 0 ) ); + + while(1) + { + /* get the actual time and date */ + DateTime time = rtcc.now( ); + /* display through serial port*/ + printf( "Actual time "); + display_DateTime( time); + + DateTime delta = time + TimeSpan(1, 0, 0, 0); // One day later with TimeSpan addition. + printf( "1 day later "); + display_DateTime( delta); + + delta = time + TimeSpan(7, 0, 0, 0); // One week later with TimeSpan addition. + printf( "one week later"); + display_DateTime( delta); + + delta = time + TimeSpan(0, 0, 30, 10); // Fourty two minutes and fourty two seconds later. + printf( "00:42:42 later"); + display_DateTime( delta); + + delta = time - TimeSpan(7, 0, 0, 0); // One week ago. + printf( "one week ago "); + display_DateTime( delta); + + printf( "\n"); + /* wait ten seconds */ + wait( 10 ); + } +}
diff -r 000000000000 -r 5e1b09cde0a8 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Feb 10 15:49:52 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/f141b2784e32 \ No newline at end of file