Lab4
Dependencies: USBHost mbed wave_player_appbd
Fork of AppBoard_Waveplayer by
main.cpp@10:c8246ac91533, 2015-03-03 (annotated)
- Committer:
- jaredwil
- Date:
- Tue Mar 03 19:21:54 2015 +0000
- Revision:
- 10:c8246ac91533
- Parent:
- 9:f1aebfbe7e78
- Child:
- 11:84161ded6baf
Part4;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 0:0d68fe822228 | 1 | #include "mbed.h" |
samux | 0:0d68fe822228 | 2 | #include "USBHostMSD.h" |
4180_1 | 9:f1aebfbe7e78 | 3 | #include "wave_player.h" |
4180_1 | 9:f1aebfbe7e78 | 4 | //mbed Application board waveplayer demo |
4180_1 | 9:f1aebfbe7e78 | 5 | //Plays the wave file "sample.wav" on the USB flash drive |
4180_1 | 9:f1aebfbe7e78 | 6 | //Outputs to onboard speaker (but at very low volume) |
4180_1 | 9:f1aebfbe7e78 | 7 | //and the Audio Out jack for connection to a set of amplified PC speakers (at higher volume) |
4180_1 | 9:f1aebfbe7e78 | 8 | //Needs a USB flash drive inserted with the wav file on it to run |
samux | 0:0d68fe822228 | 9 | |
4180_1 | 9:f1aebfbe7e78 | 10 | //Analog Out Jack |
4180_1 | 9:f1aebfbe7e78 | 11 | AnalogOut DACout(p18); |
4180_1 | 9:f1aebfbe7e78 | 12 | //On Board Speaker |
4180_1 | 9:f1aebfbe7e78 | 13 | PwmOut PWMout(p26); |
4180_1 | 9:f1aebfbe7e78 | 14 | |
4180_1 | 9:f1aebfbe7e78 | 15 | wave_player waver(&DACout,&PWMout); |
4180_1 | 9:f1aebfbe7e78 | 16 | |
4180_1 | 9:f1aebfbe7e78 | 17 | int main() |
4180_1 | 9:f1aebfbe7e78 | 18 | { |
samux | 0:0d68fe822228 | 19 | USBHostMSD msd("usb"); |
4180_1 | 9:f1aebfbe7e78 | 20 | FILE *wave_file; |
4180_1 | 9:f1aebfbe7e78 | 21 | //setup PWM hardware for a Class D style audio output |
4180_1 | 9:f1aebfbe7e78 | 22 | PWMout.period(1.0/400000.0); |
4180_1 | 9:f1aebfbe7e78 | 23 | printf("\n\n\nHello, wave world!\n"); |
4180_1 | 9:f1aebfbe7e78 | 24 | // wait until connected to a USB device |
4180_1 | 9:f1aebfbe7e78 | 25 | while(!msd.connect()) { |
samux | 0:0d68fe822228 | 26 | Thread::wait(500); |
samux | 0:0d68fe822228 | 27 | } |
jaredwil | 10:c8246ac91533 | 28 | |
jaredwil | 10:c8246ac91533 | 29 | |
4180_1 | 9:f1aebfbe7e78 | 30 | //open wav file and play it |
jaredwil | 10:c8246ac91533 | 31 | wave_file=fopen("/usb/wav3.wav","r"); |
4180_1 | 9:f1aebfbe7e78 | 32 | waver.play(wave_file); |
4180_1 | 9:f1aebfbe7e78 | 33 | fclose(wave_file); |
4180_1 | 9:f1aebfbe7e78 | 34 | //end of program |
4180_1 | 9:f1aebfbe7e78 | 35 | while(1) {}; |
samux | 0:0d68fe822228 | 36 | } |