Demo for the Clock library (real time clock driven by a Ticker).

Dependencies:   mbed Clock

Revision:
4:abbab29cf5c1
Parent:
3:0a77d653f8a6
Child:
5:dee2286a6b76
--- a/main.cpp	Mon Nov 30 11:36:44 2015 +0000
+++ b/main.cpp	Sat Apr 02 11:17:48 2016 +0000
@@ -1,7 +1,7 @@
 /**
- * Demonstrates how to use the Clock library
+ * Demo for the Clock library <https://developer.mbed.org/users/hudakz/code/Clock/>
  * 
- * Note: It's a software implemented Real Time Clock. 
+ * Note: Software implemented Real Time Clock driven by a Ticker. 
  *       No external hardware (like DS1307 or DS3231 or etc.) is needed.
  * 
  */
@@ -12,9 +12,9 @@
 Serial pc(USBTX, USBRX);
 
 
-Clock rtc;    // Create an instance of Clock class (set to 00:00:00 1 January, 1970)
+Clock rtc;    // Create an instance of Clock class (set to 00:00:00 January 1, 1970)
 
-// Create some alarms
+// Create alarms as needed
 time_t  alarm1 = Clock::asTime(2015, 3, 24, 11, 36, 15);  // year, month (1 stands for Jan etc.), day of month, hour, minute, second
 time_t  alarm2 = Clock::asTime(2015, 3, 24, 11, 37, 30); 
 
@@ -52,64 +52,64 @@
             // draw clock hands on a graphical display
             // or update digital display or etc.
             // ...
-            // In this demo we just print some info ..
+            // In this demo we just display some info on the connected PC's terminal ..
             //
-            pc.printf("==================================================\r\n");
+            pc.printf("==================================================\n");
             //time_t time = time(NULL);   // you can call C library time function if you like
             time_t time = rtc.time();     // or Clock function
-            pc.printf("Time as seconds since January 1, 1970 = %d\r\n", time);
-            pc.printf("Time as a basic string = %s\r\n", ctime(&time));
+            pc.printf("Time as seconds since January 1, 1970 = %d\n", time);
+            pc.printf("Time as a basic string = %s\n", ctime(&time));
         
             //
             // Use custom format:
             //
             char buffer[32];
             strftime(buffer, 32, "%I:%M %p", localtime(&time));
-            pc.printf("Time as a custom formatted string = %s\r\n", buffer);
+            pc.printf("Time as a custom formatted string = %s\n", buffer);
             
             //
             // Create your own format:
             //
-            pc.printf("Date:  %.4d-%.2d-%.2d\r\n", rtc.year(), rtc.mon(), rtc.mday());
-            pc.printf("Time:  %.2d:%.2d:%.2d\r\n", rtc.hour(), rtc.min(), rtc.sec());
+            pc.printf("Date:  %.4d-%.2d-%.2d\n", rtc.year(), rtc.mon(), rtc.mday());
+            pc.printf("Time:  %.2d:%.2d:%.2d\n", rtc.hour(), rtc.min(), rtc.sec());
             
             //
             // Perform periodical tasks:
             //
             if(rtc.sec() % 10 == 0) {
-                pc.printf("\r\n  Called once per 10 seconds\r\n\r\n");
+                pc.printf("Called once per 10 seconds\n");
             }
             
             if(rtc.sec() == 0) {
-                pc.printf("\r\n  Called once per minute.\r\n\r\n");
+                pc.printf("Called once per minute.\n");
                 
                 if(rtc.min() % 5 == 0)
-                    pc.printf("\r\n  Called once per 5 minutes\r\n");
+                    pc.printf("Called once per 5 minutes\n");
         
                 if(rtc.min() == 0) {
-                    pc.printf("\r\n  Called once per hour\r\n");
+                    pc.printf("\Called once per hour\n");
                     
                     if(rtc.hour() % 3 == 0)
-                        pc.printf("\r\n  Called once per 3 hours\r\n");
+                        pc.printf("Called once per 3 hours\n");
         
                     if(rtc.hour() == 0) {
-                        pc.printf("\r\n  Called at midnight\r\n");
+                        pc.printf("Called at midnight\n");
                         
                         if(rtc.wday() == 3)
-                            pc.printf("\r\n  Called on Wednesday at midnight\r\n");
+                            pc.printf("Called on Wednesday at midnight\n");
                     }
                 }
             }
         
             //
-            // Trigger alarms:
+            // Trigger the alarms:
             //
             if(rtc.time() == alarm1) {
-                pc.printf("\r\n  Alarm1 triggered!\r\n\r\n");
+                pc.printf("Alarm1 triggered!\n");
             }
         
             if(rtc.time() == alarm2) {
-                pc.printf("\r\n  Alarm2 triggered!\r\n\r\n");
+                pc.printf("Alarm2 triggered!\n");
             }
         }
     }