This sketch shows how to repeat an alarm every minute

Dependencies:   Hotboards_rtcc mbed

Files at this revision

API Documentation at this revision

Comitter:
Hotboards
Date:
Wed Feb 10 18:38:28 2016 +0000
Commit message:
first release

Changed in this revision

Hotboards_rtcc.lib Show annotated file Show diff for this revision Revisions of this file
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Hotboards_rtcc.lib	Wed Feb 10 18:38:28 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/Hotboards/code/Hotboards_rtcc/#0790bcaf8b8f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Feb 10 18:38:28 2016 +0000
@@ -0,0 +1,65 @@
+/*
+  Hotboards_rtcc Library - alarm
+ Demonstrates the use a MCP7941x clock calendar.  The Hotboards_rtcc
+ library works with this microchip real time clock 
+ (http://www.hotboards.org).
+ 
+ This sketch shows how to repeat an alarm every minute
+ 
+  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);
+
+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 when is compiled*/
+    DateTime time( __DATE__, __TIME__);
+    rtcc.adjust(time); 
+    
+    /* Set an alarm after one minute */
+    DateTime alarm = time + TimeSpan( 0, 0, 1, 0 );
+    rtcc.setAlarm( alarm );
+    /* enable the alarm */
+    rtcc.turnOnAlarm( );
+  
+    printf("The alarm will be active in one minute \n");
+
+    while(1)
+    {
+       /* is the alarm active?? */
+       if( rtcc.getAlarmStatus( ) == 1 )
+       {
+        /* clear the alarm */
+        rtcc.clearAlarm( );
+        /* display the time */
+        DateTime time = rtcc.now( );
+        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());
+        /* Set an alarm one minute after the current time, again */
+        alarm = time + TimeSpan( 0, 0, 1, 0 );
+        rtcc.setAlarm( alarm );
+       }
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Feb 10 18:38:28 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/f141b2784e32
\ No newline at end of file