9.3 Licht zeitgesteuert Ein- und Ausschalten, z.B. h:m:45 Ein, h:m:50 Aus.

Dependencies:   EthernetInterface NTPClient mbed-rtos mbed

Fork of 09-03-Uebung by th.iotkit.ch

Revision:
1:731bf468ab9f
Parent:
0:8107357917ce
Child:
2:c56233cb8520
diff -r 8107357917ce -r 731bf468ab9f main.cpp
--- a/main.cpp	Sun Feb 22 12:50:44 2015 +0000
+++ b/main.cpp	Sun Feb 22 14:02:37 2015 +0000
@@ -1,8 +1,13 @@
-/** 7.3 Eingabe der Zeit mittels Serieller Schnittstelle und Ausgabe mittels printf.
+/** 8.2 Setzen der Zeit, mittels der Seriellen Schnittstelle und Ausgabe Stunden und Minuten auf dem Display.
  * Beispiel von http://developer.mbed.org/blog/entry/103/
+ * Informationen um Zeit zu holen von http://stackoverflow.com/questions/997946/how-to-get-current-time-and-date-in-c
 */
 #include "mbed.h"
 
+#include "DigitDisplay.h"
+
+DigitDisplay display(PTC5, PTC7);
+
 int main()
 {
     // get the current time from the terminal
@@ -17,13 +22,20 @@
     t.tm_mon = t.tm_mon - 1;
 
     // set the time
-    set_time(mktime(&t));
+    set_time( mktime(&t) );
 
     // display the time
     while(1) 
     {
         time_t seconds = time(NULL);
-        printf("Time as a basic string = %s", ctime(&seconds));
+        struct tm * now = localtime( & seconds );
+        printf( "%d.%d.%d %2d:%2d:%2d\n", now->tm_mday, now->tm_mon + 1, now->tm_year + 1900, now->tm_hour, now->tm_min, now->tm_sec );
+
+        display.write(0, now->tm_min / 10);
+        display.write(1, now->tm_min % 10);
+        display.write(2, now->tm_sec  / 10);
+        display.write(3, now->tm_sec  % 10);
+
         wait(1);
     }
 }
\ No newline at end of file