Lab4
Dependencies: USBHost mbed wave_player_appbd
Fork of AppBoard_Waveplayer by
main.cpp
00001 #include "mbed.h" 00002 #include "USBHostMSD.h" 00003 #include "wave_player.h" 00004 #include "rtos.h" 00005 00006 //mbed Application board waveplayer demo 00007 //Plays the wave file "sample.wav" on the USB flash drive 00008 //Outputs to onboard speaker (but at very low volume) 00009 //and the Audio Out jack for connection to a set of amplified PC speakers (at higher volume) 00010 //Needs a USB flash drive inserted with the wav file on it to run 00011 00012 //Analog Out Jack 00013 AnalogOut DACout(p18); 00014 //On Board Speaker 00015 PwmOut PWMout(p26); 00016 00017 wave_player waver(&DACout,&PWMout); 00018 00019 void playwav(void const *args) 00020 { 00021 FILE *wave_file; 00022 wave_file=fopen((const char *)args,"r"); 00023 waver.play(wave_file); 00024 fclose(wave_file); 00025 } 00026 00027 int main() 00028 { 00029 USBHostMSD msd("usb"); 00030 //setup PWM hardware for a Class D style audio output 00031 PWMout.period(1.0/400000.0); 00032 printf("\n\n\nHello, wave world!\n"); 00033 // wait until connected to a USB device 00034 while(!msd.connect()) { 00035 Thread::wait(500); 00036 } 00037 //open wav file and play it 00038 waver.stop = false; 00039 Thread thread(playwav,(void *)"/usb/wav3.wav"); 00040 //end of program 00041 Thread::wait(10); 00042 waver.stop = true; 00043 while(1) {}; 00044 }
Generated on Sun Jul 24 2022 00:50:25 by 1.7.2