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 SDFileSystem mbed-rtos mbed wave_player_appbd
Revision 2:f4ad69c44c7e, committed 2016-02-28
- Comitter:
- wschon
- Date:
- Sun Feb 28 23:25:52 2016 +0000
- Parent:
- 1:2129bb91c172
- Child:
- 3:7d53a2744a2b
- Commit message:
- added wave player thread;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| wave_player_appbd.lib | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Feb 28 22:40:13 2016 +0000
+++ b/main.cpp Sun Feb 28 23:25:52 2016 +0000
@@ -3,12 +3,20 @@
#include "uLCD_4DGL.h"
#include "SDFileSystem.h"
#include "USBHostMSD.h"
+#include "wave_player.h"
SDFileSystem sd(p5, p6, p7, p8, "sd");
Serial pc(USBTX, USBRX);
Mutex ulcd_mutex;
uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin;
DigitalOut myled(LED1);
+//Analog Out Jack
+AnalogOut DACout(p18);
+//On Board Speaker
+PwmOut PWMout(p21);
+wave_player waver(&DACout,&PWMout);
+int playing = 1;
+
void ulcd2_thread(void const *args) {
int count = 0;
@@ -19,6 +27,10 @@
uLCD.printf("\nECE 4180 L3: RTOS\n"); //Default Green on black text
uLCD.printf("\nWes Schon Nick Liu");
uLCD.printf("\n\nThread 2 count: %d", count);
+ if (playing == 1)
+ uLCD.printf("\n\nPlaying wav file...");
+ else
+ uLCD.printf("\n\nWav file finished.");
uLCD.text_width(4); //4X size text
uLCD.text_height(4);
Thread::wait(3000);
@@ -26,9 +38,32 @@
count++;
}
}
+void wav_thread(void const *args) {
+ USBHostMSD msd("usb");
+ FILE *wave_file;
+ //setup PWM hardware for a Class D style audio output
+ PWMout.period(1.0/400000.0);
+ //printf("\n\n\nHello, wave world!\n");
+ // wait until connected to a USB device
+ while(!msd.connect()) {
+ Thread::wait(500);
+ }
+ //open wav file and play it
+ wave_file=fopen("/usb/sample.wav","r");
+ waver.play(wave_file);
+ fclose(wave_file);
+ //end of program
+ Thread::wait(500);
+ playing = 0;
+ }
+
+void led_thread(void const *args) {
+
+ }
int main() {
Thread thread(ulcd2_thread);
+ Thread thread2(wav_thread);
int count2 = 0;
while(1) {
myled = 1;
@@ -41,6 +76,10 @@
uLCD.cls();
uLCD.media_init();
uLCD.printf("\n\nThread 1 count: %d", count2);
+ if (playing == 1)
+ uLCD.printf("\n\nPlaying wav file...");
+ else
+ uLCD.printf("\n\nWav file finished.");
Thread::wait(200);
uLCD.set_sector_address(0x0000, 0x0000);
uLCD.display_video(0,0);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wave_player_appbd.lib Sun Feb 28 23:25:52 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/4180_1/code/wave_player_appbd/#b1cea7afcfd2
