8.2 Setzen der Zeit, mittels der Seriellen Schnittstelle und Ausgabe Stunden und Minuten auf dem Display.

Dependencies:   DigitDisplay mbed

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

Files at this revision

API Documentation at this revision

Comitter:
stefan1691
Date:
Sun Feb 22 14:02:37 2015 +0000
Parent:
0:8107357917ce
Commit message:
8.2 Setzen der Zeit, mittels der Seriellen Schnittstelle und Ausgabe Stunden und Minuten auf dem Display.

Changed in this revision

DigitDisplay.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
diff -r 8107357917ce -r 731bf468ab9f DigitDisplay.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DigitDisplay.lib	Sun Feb 22 14:02:37 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/Seeed/code/DigitDisplay/#d3173c8bfd48
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