Junichi Katsu / Mbed 2 deprecated LedPanel_ClockSpeaker

Dependencies:   EthernetInterface NTPClient mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003 #include "NTPClient.h"
00004 #include "LedPanel.h"
00005 #include "LedPanel_GFX.h"
00006 
00007 EthernetInterface eth;
00008 NTPClient ntp;
00009 I2C i2c(p9, p10);
00010 PwmOut spkr(p21);
00011 
00012 LedPanel matrix(&i2c);
00013 
00014 void Alarm()
00015 {
00016     spkr.period(1.0/2000.0);
00017     spkr=0.5;
00018     wait(0.5);
00019     spkr=0.0;   
00020 }
00021 
00022 char *Number2ShiftJis(char num)
00023 {
00024     short code = num + 0x824F;
00025     char ShiftJisCode[3];
00026     
00027     code = ntohs(code);
00028     memcpy( ShiftJisCode , &code , 2 );
00029     ShiftJisCode[2] = '\0';
00030     return(ShiftJisCode);
00031 }
00032 
00033 int main() 
00034 {
00035     matrix.begin(0x70,0x71);
00036     matrix.setBrightness(1);
00037     
00038     matrix.writeDisplay();
00039 
00040     eth.init(); //Use DHCP
00041 
00042     eth.connect();
00043    
00044     printf("Trying to update time...\r\n");
00045     if (ntp.setTime("ntp.nict.jp") == 0)
00046     {
00047       printf("Set time successfully\r\n");
00048       time_t ctTime;
00049       ctTime = time(NULL) + 32400;
00050       printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
00051     }
00052     else
00053     {
00054       printf("Error\r\n");
00055       return(-1);
00056     } 
00057    
00058     eth.disconnect();
00059     
00060     int old_hour = 0;
00061     int old_min = 0;
00062 
00063     while(1) {
00064         
00065         time_t ctTime;
00066         ctTime = time(NULL) + 32400;
00067 
00068         struct tm * strtim;
00069         strtim = localtime( &ctTime );
00070         
00071         if( strtim->tm_min != old_min )
00072         {
00073             old_min = strtim->tm_min;
00074             matrix.setCursor(0,0);
00075             matrix.printf("%s",Number2ShiftJis(strtim->tm_hour/10));
00076             matrix.printf("%s",Number2ShiftJis(strtim->tm_hour%10));
00077             matrix.printf("%s",Number2ShiftJis(strtim->tm_min/10));
00078             matrix.printf("%s",Number2ShiftJis(strtim->tm_min%10));
00079             matrix.writeDisplay();
00080         }
00081         if( strtim->tm_hour != old_hour )
00082         {
00083             old_hour = strtim->tm_hour;
00084             Alarm();
00085         }
00086     }
00087 }
00088