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-01-Uebung by th.iotkit.ch

Committer:
stefan1691
Date:
Sun Feb 22 12:50:44 2015 +0000
Revision:
0:8107357917ce
Child:
1:731bf468ab9f
7.3 Eingabe der Zeit mittels Serieller Schnittstelle und Ausgabe mittels printf.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stefan1691 0:8107357917ce 1 /** 7.3 Eingabe der Zeit mittels Serieller Schnittstelle und Ausgabe mittels printf.
stefan1691 0:8107357917ce 2 * Beispiel von http://developer.mbed.org/blog/entry/103/
stefan1691 0:8107357917ce 3 */
stefan1691 0:8107357917ce 4 #include "mbed.h"
stefan1691 0:8107357917ce 5
stefan1691 0:8107357917ce 6 int main()
stefan1691 0:8107357917ce 7 {
stefan1691 0:8107357917ce 8 // get the current time from the terminal
stefan1691 0:8107357917ce 9 struct tm t;
stefan1691 0:8107357917ce 10 printf("Enter current date and time:\n");
stefan1691 0:8107357917ce 11 printf("YYYY MM DD HH MM SS[enter]\n");
stefan1691 0:8107357917ce 12 scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday
stefan1691 0:8107357917ce 13 , &t.tm_hour, &t.tm_min, &t.tm_sec);
stefan1691 0:8107357917ce 14
stefan1691 0:8107357917ce 15 // adjust for tm structure required values
stefan1691 0:8107357917ce 16 t.tm_year = t.tm_year - 1900;
stefan1691 0:8107357917ce 17 t.tm_mon = t.tm_mon - 1;
stefan1691 0:8107357917ce 18
stefan1691 0:8107357917ce 19 // set the time
stefan1691 0:8107357917ce 20 set_time(mktime(&t));
stefan1691 0:8107357917ce 21
stefan1691 0:8107357917ce 22 // display the time
stefan1691 0:8107357917ce 23 while(1)
stefan1691 0:8107357917ce 24 {
stefan1691 0:8107357917ce 25 time_t seconds = time(NULL);
stefan1691 0:8107357917ce 26 printf("Time as a basic string = %s", ctime(&seconds));
stefan1691 0:8107357917ce 27 wait(1);
stefan1691 0:8107357917ce 28 }
stefan1691 0:8107357917ce 29 }