Hotboards MX / Mbed 2 deprecated Hotboards_rtcc_alarm

Dependencies:   Hotboards_rtcc mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 /*
00003   Hotboards_rtcc Library - alarm
00004  Demonstrates the use a MCP7941x clock calendar.  The Hotboards_rtcc
00005  library works with this microchip real time clock 
00006  (http://www.hotboards.org).
00007  
00008  This sketch set an single alarm that will be active 
00009  after one minute.
00010   The circuit:
00011  *  VDD  -->  3.3v
00012  *  GND  -->  GND
00013  *  SDA  -->  SDA
00014  *  SCL  -->  SCL
00015  
00016 */
00017 #include "mbed.h"
00018 #include "Hotboards_rtcc.h"
00019 
00020 /* days of the week */
00021 const char *week[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
00022 /* months of the year */
00023 const char *months[] = {"JAN","FEB","MAR","APR","MAY","JUN", "JUL", "AUG","SEPT","OCT","NOV","DEC"};
00024 
00025 /*serial port init*/
00026 Serial pc(USBTX,USBRX);
00027 /*i2c instance delaration for use with the rtcc library*/
00028 I2C device(PB_9, PB_8);
00029 /*lets declare and rtcc instance */
00030 Hotboards_rtcc rtcc(device);
00031 
00032 int main() 
00033 {
00034      /*i2c bus clock set to 100khz*/
00035     device.frequency(100000);
00036     /* init the rtcc, just enable the clock if not already enable */
00037     rtcc.begin();
00038     /* set the time when is compiled*/
00039     DateTime time( __DATE__, __TIME__);
00040     rtcc.adjust(time); 
00041     
00042     /* Set an alarm after one minute */
00043     DateTime alarm = time + TimeSpan( 0, 0, 1, 0 );
00044     rtcc.setAlarm( alarm );
00045     /* enable the alarm */
00046     rtcc.turnOnAlarm( );
00047   
00048     printf("The alarm will be active in one minute \n");
00049 
00050     while(1)
00051     {
00052        /* is the alarm active?? */
00053        if( rtcc.getAlarmStatus( ) == 1 )
00054        {
00055         /* clear the alarm */
00056         rtcc.clearAlarm( );
00057         /* display the time */
00058         DateTime time = rtcc.now( );
00059         printf( "Alarm active at:  Time- %d:%d:%d  Date-  %s/ %d/ %s/ %d\n",time.hour( ),time.minute( ),time.second( ),week[time.dayOfTheWeek( )],time.day( ),months[time.month( )],time.year());
00060        }
00061     }
00062 }