This sketch shows how to repeat an alarm every minute

Dependencies:   Hotboards_rtcc mbed

Committer:
Hotboards
Date:
Wed Feb 10 18:38:28 2016 +0000
Revision:
0:fe2da4d649de
first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Hotboards 0:fe2da4d649de 1 /*
Hotboards 0:fe2da4d649de 2 Hotboards_rtcc Library - alarm
Hotboards 0:fe2da4d649de 3 Demonstrates the use a MCP7941x clock calendar. The Hotboards_rtcc
Hotboards 0:fe2da4d649de 4 library works with this microchip real time clock
Hotboards 0:fe2da4d649de 5 (http://www.hotboards.org).
Hotboards 0:fe2da4d649de 6
Hotboards 0:fe2da4d649de 7 This sketch shows how to repeat an alarm every minute
Hotboards 0:fe2da4d649de 8
Hotboards 0:fe2da4d649de 9 The circuit:
Hotboards 0:fe2da4d649de 10 * VDD --> 3.3v
Hotboards 0:fe2da4d649de 11 * GND --> GND
Hotboards 0:fe2da4d649de 12 * SDA --> SDA
Hotboards 0:fe2da4d649de 13 * SCL --> SCL
Hotboards 0:fe2da4d649de 14
Hotboards 0:fe2da4d649de 15 */
Hotboards 0:fe2da4d649de 16 #include "mbed.h"
Hotboards 0:fe2da4d649de 17 #include "Hotboards_rtcc.h"
Hotboards 0:fe2da4d649de 18
Hotboards 0:fe2da4d649de 19 /* days of the week */
Hotboards 0:fe2da4d649de 20 const char *week[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
Hotboards 0:fe2da4d649de 21 /* months of the year */
Hotboards 0:fe2da4d649de 22 const char *months[] = {"JAN","FEB","MAR","APR","MAY","JUN", "JUL", "AUG","SEPT","OCT","NOV","DEC"};
Hotboards 0:fe2da4d649de 23
Hotboards 0:fe2da4d649de 24 /*serial port init*/
Hotboards 0:fe2da4d649de 25 Serial pc(USBTX,USBRX);
Hotboards 0:fe2da4d649de 26 /*i2c instance delaration for use with the rtcc library*/
Hotboards 0:fe2da4d649de 27 I2C device(PB_9, PB_8);
Hotboards 0:fe2da4d649de 28 /*lets declare and rtcc instance */
Hotboards 0:fe2da4d649de 29 Hotboards_rtcc rtcc(device);
Hotboards 0:fe2da4d649de 30
Hotboards 0:fe2da4d649de 31 int main()
Hotboards 0:fe2da4d649de 32 {
Hotboards 0:fe2da4d649de 33 /*i2c bus clock set to 100khz*/
Hotboards 0:fe2da4d649de 34 device.frequency(100000);
Hotboards 0:fe2da4d649de 35 /* init the rtcc, just enable the clock if not already enable */
Hotboards 0:fe2da4d649de 36 rtcc.begin();
Hotboards 0:fe2da4d649de 37 /* set the time when is compiled*/
Hotboards 0:fe2da4d649de 38 DateTime time( __DATE__, __TIME__);
Hotboards 0:fe2da4d649de 39 rtcc.adjust(time);
Hotboards 0:fe2da4d649de 40
Hotboards 0:fe2da4d649de 41 /* Set an alarm after one minute */
Hotboards 0:fe2da4d649de 42 DateTime alarm = time + TimeSpan( 0, 0, 1, 0 );
Hotboards 0:fe2da4d649de 43 rtcc.setAlarm( alarm );
Hotboards 0:fe2da4d649de 44 /* enable the alarm */
Hotboards 0:fe2da4d649de 45 rtcc.turnOnAlarm( );
Hotboards 0:fe2da4d649de 46
Hotboards 0:fe2da4d649de 47 printf("The alarm will be active in one minute \n");
Hotboards 0:fe2da4d649de 48
Hotboards 0:fe2da4d649de 49 while(1)
Hotboards 0:fe2da4d649de 50 {
Hotboards 0:fe2da4d649de 51 /* is the alarm active?? */
Hotboards 0:fe2da4d649de 52 if( rtcc.getAlarmStatus( ) == 1 )
Hotboards 0:fe2da4d649de 53 {
Hotboards 0:fe2da4d649de 54 /* clear the alarm */
Hotboards 0:fe2da4d649de 55 rtcc.clearAlarm( );
Hotboards 0:fe2da4d649de 56 /* display the time */
Hotboards 0:fe2da4d649de 57 DateTime time = rtcc.now( );
Hotboards 0:fe2da4d649de 58 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());
Hotboards 0:fe2da4d649de 59 /* Set an alarm one minute after the current time, again */
Hotboards 0:fe2da4d649de 60 alarm = time + TimeSpan( 0, 0, 1, 0 );
Hotboards 0:fe2da4d649de 61 rtcc.setAlarm( alarm );
Hotboards 0:fe2da4d649de 62 }
Hotboards 0:fe2da4d649de 63 }
Hotboards 0:fe2da4d649de 64 }
Hotboards 0:fe2da4d649de 65