Smart Clock

Dependencies:   AlarmClock DigitalClock EthernetInterface FourDigitLED HTTPClient NTPClient SDFileSystem TrainStat WeatherInfo XML_aide mbed-rtos mbed picojson wolfSSL

Committer:
takashikojo
Date:
Thu Jun 25 23:31:17 2015 +0000
Revision:
0:0689619f2486
Child:
1:1a28aaca601d
Initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takashikojo 0:0689619f2486 1 #include "mbed.h"
takashikojo 0:0689619f2486 2
takashikojo 0:0689619f2486 3 #include "EthernetInterface.h"
takashikojo 0:0689619f2486 4 #include "NTPClient.h"
takashikojo 0:0689619f2486 5 #include "AlarmClock.h"
takashikojo 0:0689619f2486 6
takashikojo 0:0689619f2486 7 static AlarmClock alarmclock (
takashikojo 0:0689619f2486 8 /* Segment 0 - 6, Dot */ D11,D6, D3, D1, D0, D10,D4, D2 ,
takashikojo 0:0689619f2486 9 /* Digit 1 - 4 */ D5, D7, D9, D12,
takashikojo 0:0689619f2486 10 /* Alarm, Hour, Min, Tone */D13, D14, D15, PTC11
takashikojo 0:0689619f2486 11 ) ;
takashikojo 0:0689619f2486 12
takashikojo 0:0689619f2486 13 static EthernetInterface eth;
takashikojo 0:0689619f2486 14
takashikojo 0:0689619f2486 15 void clock_main(void const *av)
takashikojo 0:0689619f2486 16 {
takashikojo 0:0689619f2486 17 int ret ;
takashikojo 0:0689619f2486 18 NTPClient ntp;
takashikojo 0:0689619f2486 19 alarmclock.setLED(11, 11) ;
takashikojo 0:0689619f2486 20 ret = eth.init();
takashikojo 0:0689619f2486 21 alarmclock.setLED(22, 22) ;
takashikojo 0:0689619f2486 22 while(1) {
takashikojo 0:0689619f2486 23 ret = eth.connect();
takashikojo 0:0689619f2486 24 if(ret == 0)break ;
takashikojo 0:0689619f2486 25 Thread::wait(10);
takashikojo 0:0689619f2486 26 }
takashikojo 0:0689619f2486 27 alarmclock.setLED(33, 33) ;
takashikojo 0:0689619f2486 28 if (ntp.setTime("ntp.jst.mfeed.ad.jp") == 0) {
takashikojo 0:0689619f2486 29 alarmclock.flashLED() ;
takashikojo 0:0689619f2486 30 } else {
takashikojo 0:0689619f2486 31 alarmclock.setLED(0, 0) ;
takashikojo 0:0689619f2486 32 wait(30.0) ;
takashikojo 0:0689619f2486 33 return ;
takashikojo 0:0689619f2486 34 }
takashikojo 0:0689619f2486 35 alarmclock.start() ;
takashikojo 0:0689619f2486 36 while(1){
takashikojo 0:0689619f2486 37 alarmclock.poll() ;
takashikojo 0:0689619f2486 38 Thread::wait(100);
takashikojo 0:0689619f2486 39 }
takashikojo 0:0689619f2486 40 }
takashikojo 0:0689619f2486 41
takashikojo 0:0689619f2486 42 int main() {
takashikojo 0:0689619f2486 43 #define STACK_SIZE 16000
takashikojo 0:0689619f2486 44 Thread t(clock_main, NULL, osPriorityNormal, STACK_SIZE);
takashikojo 0:0689619f2486 45 while(1)Thread::wait(1000);
takashikojo 0:0689619f2486 46 }