Lab4

Dependencies:   USBHost mbed wave_player_appbd

Fork of AppBoard_Waveplayer by jim hamblen

Committer:
4180_1
Date:
Fri Nov 01 15:30:47 2013 +0000
Revision:
9:f1aebfbe7e78
Parent:
4:f8a5c8aa895a
Child:
10:c8246ac91533
A wave player demo setup for the mbed application board
; Reads a wave file from a USB flash drive, and outputs to the onboard speaker (low volume) and the audio out jack that can be connected to a set of PC speakers.

Who changed what in which revision?

UserRevisionLine numberNew 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 }
4180_1 9:f1aebfbe7e78 28 //open wav file and play it
4180_1 9:f1aebfbe7e78 29 wave_file=fopen("/usb/sample.wav","r");
4180_1 9:f1aebfbe7e78 30 waver.play(wave_file);
4180_1 9:f1aebfbe7e78 31 fclose(wave_file);
4180_1 9:f1aebfbe7e78 32 //end of program
4180_1 9:f1aebfbe7e78 33 while(1) {};
samux 0:0d68fe822228 34 }