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
main.cpp
- Committer:
- stefan1691
- Date:
- 2015-02-22
- Revision:
- 2:c56233cb8520
- Parent:
- 1:731bf468ab9f
- Child:
- 3:ca2a69bdba22
File content as of revision 2:c56233cb8520:
/** 9.2 Holen der Zeit vom Internet, interne Uhr setzen und Ausgabe auf Display * Informationen um Zeit zu holen von http://stackoverflow.com/questions/997946/how-to-get-current-time-and-date-in-c */ #include "mbed.h" #include "EthernetInterface.h" #include "NTPClient.h" #include "DigitDisplay.h" EthernetInterface eth; NTPClient ntp; DigitDisplay display(PTC5, PTC7); int main() { // Ethernet Interface Initialisieren printf("Initialize Ethernet\n" ); eth.init(); eth.connect(); // Zeit vom Time Server holen printf("Trying to update time...\r\n"); if (ntp.setTime("1.pool.ntp.org") == 0) { printf("Set time successfully\r\n"); time_t ctTime; ctTime = time(NULL); printf("Time is set to (UTC): %s\r\n", ctime(&ctTime)); } else printf("Error\r\n"); eth.disconnect(); // display the time while(1) { time_t seconds = time(NULL); 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); } }