First Final Version, Will probably need revision with regards to LCD and maybe the clock

Dependencies:   mbed HTTPClient MMA8452Q mbed-rtos 4DGL-uLCD-SE NTPClient SDFileSystem1 EthernetInterface

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers alarm.h Source File

alarm.h

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003 #include "NTPClient.h"
00004 #include "uLCD_4DGL.h"
00005 
00006 #define VOLUME 1
00007 // Parameters
00008 int port_number = 123;
00009 
00010 // Networking
00011 EthernetInterface eth;
00012 NTPClient ntpClient;
00013 
00014 //Pins
00015 PwmOut pwm_pin(p21);
00016 DigitalIn button(p12);
00017 BusOut LEDS(LED1,LED2,LED3,LED4);
00018 uLCD_4DGL uLCD(p9,p10,p11);
00019 
00020 // Plays a sound with the defined frequency, duration, and volume
00021 void playNote(float frequency, float duration, float volume) {
00022     pwm_pin.period(1.0/frequency);
00023     pwm_pin = volume/2.0;
00024     wait(duration);
00025     pwm_pin = 0.0;
00026 }
00027 
00028 void soundalarm()
00029 {
00030     time_t ctTime; 
00031     eth.init();
00032     eth.connect();
00033     
00034     char* domainName="0.uk.pool.ntp.org";
00035     //Initilaise LCD
00036     uLCD.baudrate(115200);
00037 
00038     // Read time from server
00039     ntpClient.setTime(domainName,123,0x00005000);
00040     //Buffers for holding time when the alarm begins and ends
00041     char buffer1[80];
00042     char buffer2[80];
00043     wait(2);
00044     eth.disconnect();
00045     ctTime = time(NULL); 
00046     strftime(buffer1, 80, "    %a %b %d\n    %T %p %z\n    %Z\n", \
00047                                                 localtime(&ctTime));
00048     // Loop
00049     while((button==1))
00050      {   
00051     playNote(960,1.2,VOLUME);
00052     LEDS=0x0F;
00053     wait(0.1);
00054     playNote(770,1.2,VOLUME);
00055     LEDS=0;
00056     }
00057     uLCD.locate(0,12);
00058     uLCD.printf("Alarm Began On:\n");
00059     uLCD.printf("    UTC/GMT:\n%s", buffer1); 
00060     ctTime = time(NULL); 
00061     strftime(buffer2, 80, "    %a %b %d\n    %T %p %z\n    %Z\n", \
00062                                                 localtime(&ctTime));
00063     wait(30);                               
00064 }
00065 
00066 
00067 
00068 
00069 
00070