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
Diff: main.cpp
- Revision:
- 4:35afb6a34591
- Parent:
- 3:ca2a69bdba22
--- a/main.cpp Sun Feb 22 14:19:22 2015 +0000 +++ b/main.cpp Sun Feb 22 14:30:18 2015 +0000 @@ -1,4 +1,4 @@ -/** 9.1 Holen der Zeit vom Internet und interne Uhr setzen +/** 9.3 Licht zeitgesteuert Ein- und Ausschalten, z.B. h:m:45 Ein, h:m:50 Aus. * Informationen um Zeit zu holen von http://stackoverflow.com/questions/997946/how-to-get-current-time-and-date-in-c */ #include "mbed.h" @@ -8,6 +8,9 @@ EthernetInterface eth; NTPClient ntp; +// Licht +DigitalOut led( D10 ); + int main() { // Ethernet Interface Initialisieren @@ -34,6 +37,16 @@ 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 ); + + // h:m:15 Ein, h:m:20 Aus. + if ( now->tm_sec >= 15 && now->tm_sec <= 20 ) + led = 1; + // h:m:45 Ein, h:m:50 Aus. + else if ( now->tm_sec >= 45 && now->tm_sec <= 50 ) + led = 1; + else + led = 0; + wait(1); } } \ No newline at end of file