Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE EthernetInterface NTPClient TextLCD mbed PinDetect SDFileSystem wave_player mbed-rtos
Fork of Internet_LCD_Clock by
Revision 5:818735a07b88, committed 2016-04-20
- Comitter:
- ashea6
- Date:
- Wed Apr 20 20:28:20 2016 +0000
- Parent:
- 4:9c06e27ebc20
- Child:
- 6:e08b5dbdfbcf
- Commit message:
- wave error
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Wed Apr 20 20:28:20 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/4180/code/EthernetInterface/#cf25ea606241
--- a/EthernetNetIf.lib Mon Apr 11 17:58:47 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
--- a/Internet_LCD_Clock.cpp Mon Apr 11 17:58:47 2016 +0000
+++ b/Internet_LCD_Clock.cpp Wed Apr 20 20:28:20 2016 +0000
@@ -1,52 +1,105 @@
#include "mbed.h"
-#include "EthernetNetIf.h"
+//#include "EthernetNetIf.h"
#include "NTPClient.h"
+#include "EthernetInterface.h"
#include "uLCD_4DGL.h"
#include "Speaker.h"
#include "SDFileSystem.h"
#include "wave_player.h"
+#include "PinDetect.h"
+
+
#include <vector>
#include <string>
+// Parameters
+char* domain_name = "0.uk.pool.ntp.org";
+int port_number = 123;
+
+// Networking
+EthernetInterface eth;
+NTPClient ntp_client;
+
// Internet of Things clock example: LCD time is set via internet NTP time server
-uLCD_4DGL lcd(p28,p27,p29); // create a global LCD object
-EthernetNetIf eth;
-NTPClient ntp;
-SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
+uLCD_4DGL uLCD(p28,p27,p29); // create a global LCD object
+//EthernetNetIf eth;
+//NTPClient ntp;
+SDFileSystem sd(p11, p12, p13, p14, "sd"); //SD card
AnalogOut DACout(p18); //speaker
wave_player waver(&DACout);
-PinDetect snooze(p15); //snooze button
-PinDetect off(p16); //turn alarm off
+PinDetect snooze(p19); //snooze button
+PinDetect off(p20); //turn alarm off
+DigitalIn sdd(p12);
+DigitalOut myled1(LED1);
+DigitalOut myled2(LED2);
-#define snoozeTime 420
+#define snoozeTime 60
//Global Variables
//variables for SD sound
-vector <string> filenames;
+vector <string> filenames;
int current = 0;
-bool play = false; sd_insert = false;
+bool playing = false;
+bool sd_insert = false;
static int veclen = 5;
FILE *wave_file;
-//variables for alarm
+//variables for alarm
//system time structure
time_t ctTime; //ctTime = current time
-// Base alarm time-24 hour clock
+// Base alarm time-24 hour clock
int baseAlarmHour = 0; //0-23
-int baseAlarmMin = 0;
+int baseAlarmMin = 0;
// Current alarm time
-int curAlarmHour = 0; //0-23
-int curAlarmMin = 0;
+int curAlarmHour = 18; //0-23
+int curAlarmMin = 9;
+//SongPlayer mySpeaker(p26);
+Ticker flippera;
+
+//alarm tone
+float note[17]= {1568.0,1396.9,1244.5,1244.5,1396.9,1568.0,1568.0,1568.0,1396.9,
+ 1244.5,1396.9,1568.0,1396.9,1244.5,1174.7,1244.5,1244.5,
+ };
+float duration[17]= {0.48,0.24,0.72,0.48,0.24,0.48,0.24,0.24,0.24,
+ 0.24,0.24,0.24,0.24,0.48,0.24,0.48,0.48
+ };
+
+void flip_time()
+{
+ myled1 = !myled1;
+ char time_buffer[80];
+ uLCD.locate(0, 1);
+ ctTime = time(NULL);
+ strftime(time_buffer, 80, " %a %b %d\n %T %p %z\n %Z\n", \
+ localtime(&ctTime));
+ uLCD.printf(" UTC/GMT:\n%s", time_buffer);
+}
+
+void thread_time(void const *args)
+{
+ while(1) {
+ myled1 = !myled1;
+ char time_buffer[80];
+ uLCD.locate(0, 1);
+ ctTime = time(NULL);
+ strftime(time_buffer, 80, " %a %b %d\n %T %p %z\n %Z\n", \
+ localtime(&ctTime));
+ uLCD.printf(" UTC/GMT:\n%s", time_buffer);
+ Thread::wait(1000);
+ }
+}
+
//Check for SD Card
-void sd_check(){
+void sd_check()
+{
int sdPre = sdd.read();
- while (sdPre == 0){
- lcd.locate(0,0);
- lcd.printf("Insert SD card");
+ while (sdPre == 0) {
+ uLCD.locate(0,0);
+ uLCD.printf("Insert SD card");
sdPre = sdd.read();
wait (.5);
}
- lcd.cls();
+ uLCD.cls();
}
//Read File Names
@@ -64,12 +117,14 @@
//Play file from SD card
void play_file()
{
- bool* play_point = &play;
- string file_name("/sd/");
- file_name += filenames[current];
- wave_file = fopen(file_name.c_str(),"r");
- while(play){
+ bool* play_point = &playing;
+ //string file_name("/sd/");
+ //file_name += filenames[current];
+ // wave_file = fopen(file_name.c_str(),"r");
+ wave_file=fopen("/sd/bob.wav","r");
+ while(playing) {
waver.play(wave_file, play_point);
+ // mySpeaker.PlaySong(note,duration);
}
fclose(wave_file);
}
@@ -77,75 +132,103 @@
//Interrupt-Snooze Function
void snooze_hit_callback (void)
{
- play = false;
- time_t = newtime;
+ myled1 = !myled1;
+ playing = false;
+ time_t newtime;
struct tm * timeinfo;
-
+
newtime = ctTime + snoozeTime;
+// time (&newtime);
timeinfo = localtime (&newtime);
- curAlarmMin = timeinfo.tm_min;
- curAlarmHour = timeinfo.tm_hour;
+ curAlarmMin = timeinfo->tm_min;
+ curAlarmHour = timeinfo->tm_hour;
}
-//Interrupt- Off Function
+//Interrupt- Off Function
void off_hit_callback (void)
{
- play = false;
+ myled2 = !myled2;
+ playing = false;
curAlarmMin = baseAlarmMin;
curAlarmHour = baseAlarmHour;
}
//Time Compare Function
void timeCompare()
{
- struct tm * timeinfo;
-
- //time(&ctTime);
- timeinfo = localtime (&ctTime);
- if (timeinfo.tm_min == curAlarmMin && timeinfo.tm_hour == curAlarmHour)
- {
- play = true;
- play_file();
- }
-}
+ struct tm * timeinfo;
+
+ //time(&ctTime);
+ timeinfo = localtime (&ctTime);
+ if (timeinfo->tm_min == curAlarmMin && timeinfo->tm_hour == curAlarmHour) {
+ playing = true;
+ play_file();
+
+ }
+}
-int main() {
+int main()
+{
snooze.mode(PullUp);
off.mode(PullUp);
- wait(.01);
+ wait(0.01);
snooze.attach_deasserted(&snooze_hit_callback);
off.attach_deasserted(&off_hit_callback);
snooze.setSampleFrequency();
off.setSampleFrequency();
-
- //clear LCD
- lcd.cls();
- // lcd.printf prints to LCD display;
- lcd.printf("Get IP addr...");
- EthernetErr ethErr = eth.setup();
- //Get an Internet IP address using DHCP
- if (ethErr) {
- //error or timeout getting an IP address
- lcd.cls();
- lcd.printf("Network Error \n\r %d",ethErr);
+
+ //time_t ct_time;
+
+
+ // Initialize LCD
+ uLCD.baudrate(115200);
+ uLCD.background_color(BLACK);
+ uLCD.cls();
+
+ // Connect to network and wait for DHCP
+ uLCD.locate(0,0);
+ uLCD.printf("Getting IP Address\n");
+ eth.init();
+ if ( eth.connect(60000) == -1 ) {
+ uLCD.printf("ERROR: Could not\nget IP address");
return -1;
}
- lcd.cls();
- lcd.printf("Reading Time...\n\r");
- //specify time server URL
- Host server(IpAddr(), 123, "0.uk.pool.ntp.org");
- //Read time from server
- ntp.setTime(server);
- lcd.printf("Time set");
- //Delay for human time to read LCD display
+ uLCD.printf("IP address is \n%s\n\n",eth.getIPAddress());
wait(1);
+
+ // Read time from server
+ uLCD.printf("Reading time...\n\r");
+ ntp_client.setTime(domain_name, port_number);
+ uLCD.printf("Time set\n");
+ wait(2);
+ eth.disconnect();
+
+ // Reset LCD
+ uLCD.background_color(WHITE);
+ uLCD.textbackground_color(WHITE);
+ uLCD.color(RED);
+ uLCD.cls();
+ uLCD.text_height(2);
+
+ // flippera.attach(&flip_time, 1.0);
+ Thread time_thread(thread_time);
+
+ // Loop and update clock
while (1) {
- // loop and periodically update the LCD's time display
- lcd.cls();
+ /*
+ myled1 = !myled1;
+ char time_buffer[80];
+ uLCD.locate(0, 1);
ctTime = time(NULL);
- lcd.printf("UTC: %s", ctime(&ctTime));
+ strftime(time_buffer, 80, " %a %b %d\n %T %p %z\n %Z\n", \
+ localtime(&ctTime));
+ uLCD.printf(" UTC/GMT:\n%s", time_buffer);
+ */
timeCompare();
- wait(.25);
+ wait(0.1);
+
}
+
+
}
--- a/NTPClient.lib Mon Apr 11 17:58:47 2016 +0000 +++ b/NTPClient.lib Wed Apr 20 20:28:20 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/donatien/code/NTPClient/#881559865a93 +http://developer.mbed.org/users/sparkfun/code/NTPClient/#881559865a93
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Speaker.h Wed Apr 20 20:28:20 2016 +0000
@@ -0,0 +1,19 @@
+#include "mbed.h"
+// new class to play a note on Speaker based on PwmOut class
+class Speaker
+{
+public:
+ Speaker(PinName pin) : _pin(pin) {
+// _pin(pin) means pass pin to the Speaker Constructor
+ }
+// class method to play a note based on PwmOut class
+ void PlayNote(float frequency, float duration, float volume) {
+ _pin.period(1.0/frequency);
+ _pin = volume/2.0;
+ wait(duration);
+ _pin = 0.0;
+ }
+
+private:
+ PwmOut _pin;
+};
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Wed Apr 20 20:28:20 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#b4c5542476ba
--- a/mbed.bld Mon Apr 11 17:58:47 2016 +0000 +++ b/mbed.bld Wed Apr 20 20:28:20 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da +http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96 \ No newline at end of file
--- a/wave_player.lib Mon Apr 11 17:58:47 2016 +0000 +++ b/wave_player.lib Wed Apr 20 20:28:20 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/sravet/code/wave_player/#acc3e18e77ad +https://developer.mbed.org/teams/4180/code/wave_player/#ab8c3f888b64
