wave cancel

Dependencies:   4DGL-uLCD-SE EthernetInterface HTTPClient NTPClient PinDetect SDFileSystem mbed-rtos mbed wave_player

Fork of 4180_Final_Project by Adam Zuravleff

Committer:
ashea6
Date:
Fri Apr 22 17:20:59 2016 +0000
Revision:
4:55035e20ae61
Parent:
3:5f0b28699a67
Child:
5:3c880df67e2e
play_file function

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashea6 2:4d370e3f4618 1 //WavePlayer_HelloWorld4180
ashea6 2:4d370e3f4618 2 //internet_clock
4180_1 1:5b8e223e983d 3
4180_1 1:5b8e223e983d 4 #include "mbed.h"
4180_1 1:5b8e223e983d 5 #include "SDFileSystem.h"
4180_1 1:5b8e223e983d 6 #include "wave_player.h"
ashea6 2:4d370e3f4618 7 #include "EthernetInterface.h"
ashea6 2:4d370e3f4618 8 #include "NTPClient.h"
ashea6 2:4d370e3f4618 9 #include "uLCD_4DGL.h"
ashea6 2:4d370e3f4618 10 #include "rtos.h"
ashea6 3:5f0b28699a67 11 #include "PinDetect.h"
4180_1 1:5b8e223e983d 12
ashea6 3:5f0b28699a67 13 //pinouts
ashea6 2:4d370e3f4618 14 SDFileSystem sd(p11, p12, p13, p14, "sd"); //SD card
4180_1 1:5b8e223e983d 15 AnalogOut DACout(p18);
4180_1 1:5b8e223e983d 16 wave_player waver(&DACout);
ashea6 3:5f0b28699a67 17 PinDetect snooze(p19); //snooze button
ashea6 3:5f0b28699a67 18 PinDetect off(p20); //turn alarm off
ashea6 3:5f0b28699a67 19 DigitalOut myled1(LED1);
ashea6 3:5f0b28699a67 20 DigitalOut myled2(LED2);
4180_1 1:5b8e223e983d 21
ashea6 2:4d370e3f4618 22 // Parameters
ashea6 2:4d370e3f4618 23 char* domain_name = "0.uk.pool.ntp.org";
ashea6 2:4d370e3f4618 24 int port_number = 123;
ashea6 2:4d370e3f4618 25
ashea6 2:4d370e3f4618 26 // Networking
ashea6 2:4d370e3f4618 27 EthernetInterface eth;
ashea6 2:4d370e3f4618 28 NTPClient ntp_client;
ashea6 2:4d370e3f4618 29
ashea6 2:4d370e3f4618 30 // Graphic LCD - TX, RX, and RES pins
ashea6 2:4d370e3f4618 31 uLCD_4DGL uLCD(p28,p27,p29);
ashea6 2:4d370e3f4618 32
ashea6 2:4d370e3f4618 33 //global variables
ashea6 2:4d370e3f4618 34 time_t ct_time;
ashea6 2:4d370e3f4618 35
ashea6 3:5f0b28699a67 36 //time thread
ashea6 2:4d370e3f4618 37 void time_thread(void const *args)
ashea6 2:4d370e3f4618 38 {
ashea6 2:4d370e3f4618 39
ashea6 2:4d370e3f4618 40 char time_buffer[80];
ashea6 2:4d370e3f4618 41 // Loop and update clock
ashea6 2:4d370e3f4618 42 while (1) {
ashea6 2:4d370e3f4618 43 uLCD.locate(0, 1);
ashea6 2:4d370e3f4618 44 ct_time = time(NULL);
ashea6 2:4d370e3f4618 45 strftime(time_buffer, 80, " %a %b %d\n %T %p %z\n %Z\n", \
ashea6 2:4d370e3f4618 46 localtime(&ct_time));
ashea6 2:4d370e3f4618 47 uLCD.printf(" UTC/GMT:\n%s", time_buffer);
ashea6 2:4d370e3f4618 48 Thread::wait(100);
ashea6 2:4d370e3f4618 49 }
ashea6 2:4d370e3f4618 50 }
ashea6 2:4d370e3f4618 51
ashea6 3:5f0b28699a67 52 //pushbutton (p19)
ashea6 3:5f0b28699a67 53 void snooze_hit_callback (void)
ashea6 3:5f0b28699a67 54 {
ashea6 3:5f0b28699a67 55 myled1 = !myled1;
ashea6 3:5f0b28699a67 56 }
ashea6 3:5f0b28699a67 57
ashea6 3:5f0b28699a67 58 void off_hit_callback (void)
ashea6 3:5f0b28699a67 59 {
ashea6 3:5f0b28699a67 60 myled2 = !myled2;
ashea6 3:5f0b28699a67 61 }
ashea6 3:5f0b28699a67 62
ashea6 4:55035e20ae61 63 void play_file()
ashea6 4:55035e20ae61 64 {
ashea6 4:55035e20ae61 65 FILE *wave_file;
ashea6 4:55035e20ae61 66 printf("\n\n\nHello, wave world!\n");
ashea6 4:55035e20ae61 67 wave_file=fopen("/sd/bob.wav","r");
ashea6 4:55035e20ae61 68 waver.play(wave_file);
ashea6 4:55035e20ae61 69 fclose(wave_file);
ashea6 4:55035e20ae61 70 }
4180_1 1:5b8e223e983d 71 int main()
4180_1 1:5b8e223e983d 72 {
ashea6 3:5f0b28699a67 73 snooze.mode(PullUp);
ashea6 3:5f0b28699a67 74 off.mode(PullUp);
ashea6 3:5f0b28699a67 75 wait(0.01);
ashea6 3:5f0b28699a67 76 snooze.attach_deasserted(&snooze_hit_callback);
ashea6 3:5f0b28699a67 77 off.attach_deasserted(&off_hit_callback);
ashea6 3:5f0b28699a67 78 snooze.setSampleFrequency();
ashea6 3:5f0b28699a67 79 off.setSampleFrequency();
ashea6 2:4d370e3f4618 80
ashea6 2:4d370e3f4618 81
ashea6 2:4d370e3f4618 82
ashea6 2:4d370e3f4618 83 // Initialize LCD
ashea6 2:4d370e3f4618 84 uLCD.baudrate(115200);
ashea6 2:4d370e3f4618 85 uLCD.background_color(BLACK);
ashea6 2:4d370e3f4618 86 uLCD.cls();
ashea6 2:4d370e3f4618 87
ashea6 2:4d370e3f4618 88 // Connect to network and wait for DHCP
ashea6 2:4d370e3f4618 89 uLCD.locate(0,0);
ashea6 2:4d370e3f4618 90 uLCD.printf("Getting IP Address\n");
ashea6 2:4d370e3f4618 91 eth.init();
ashea6 2:4d370e3f4618 92 if ( eth.connect(60000) == -1 ) {
ashea6 2:4d370e3f4618 93 uLCD.printf("ERROR: Could not\nget IP address");
ashea6 2:4d370e3f4618 94 return -1;
ashea6 2:4d370e3f4618 95 }
ashea6 2:4d370e3f4618 96 uLCD.printf("IP address is \n%s\n\n",eth.getIPAddress());
ashea6 2:4d370e3f4618 97 Thread::wait(1000);
ashea6 2:4d370e3f4618 98
ashea6 2:4d370e3f4618 99 // Read time from server
ashea6 2:4d370e3f4618 100 uLCD.printf("Reading time...\n\r");
ashea6 2:4d370e3f4618 101 ntp_client.setTime(domain_name, port_number);
ashea6 2:4d370e3f4618 102 uLCD.printf("Time set\n");
ashea6 2:4d370e3f4618 103 Thread::wait(2000);
ashea6 2:4d370e3f4618 104 eth.disconnect();
ashea6 2:4d370e3f4618 105
ashea6 2:4d370e3f4618 106 // Reset LCD
ashea6 2:4d370e3f4618 107 uLCD.background_color(WHITE);
ashea6 2:4d370e3f4618 108 uLCD.textbackground_color(WHITE);
ashea6 2:4d370e3f4618 109 uLCD.color(RED);
ashea6 2:4d370e3f4618 110 uLCD.cls();
ashea6 2:4d370e3f4618 111 uLCD.text_height(2);
ashea6 2:4d370e3f4618 112
ashea6 2:4d370e3f4618 113 Thread thread_time(time_thread);
ashea6 2:4d370e3f4618 114
ashea6 4:55035e20ae61 115 play_file();
ashea6 4:55035e20ae61 116
4180_1 1:5b8e223e983d 117 }