This program utilizes an LCD, RPG, 8 ohm speaker, and SD card to provide the basic functions of a music player. The project cycles through the SD card for .wav files and tracks elapsed time. See http://mbed.org/users/rsartin3/notebook/wav-player-with-RPG-based-menu/ for more information.
Dependencies: DebounceIn RPG SDFileSystem TextLCD mbed wav_header wave_player
Fork of Audio_Player by
Revision 2:d9953793444c, committed 2013-03-05
- Comitter:
- rsartin3
- Date:
- Tue Mar 05 16:36:15 2013 +0000
- Parent:
- 1:f31b40073d35
- Commit message:
- Changed name for clarification;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r f31b40073d35 -r d9953793444c main.cpp --- a/main.cpp Tue Mar 05 06:34:43 2013 +0000 +++ b/main.cpp Tue Mar 05 16:36:15 2013 +0000 @@ -1,5 +1,6 @@ /* * Audio Player + * Josh Dunn & Ryan Sartin */ #include "mbed.h" @@ -170,6 +171,11 @@ } void songClock() { +/* +* songClock +* Reads in time and compares it to time_i, the global variable +* Used with Ticker API to count number of seconds elapsed since song started playing +*/ time_t time_f; time_f = time(NULL); @@ -186,9 +192,11 @@ bool firstList = false; // Is it first instance of reading from SD card bool playlistExist = false; + // RPG Variables int rpgTick = 0; // Slow down RPG turning speed const int rpgThresh = 5; + // File interaction variables FILE *wave_file; string mySongName = "Invalid"; unsigned char wave_array[30]; @@ -219,8 +227,8 @@ while(1) { // ------------- No SD Card Detected ------------- // Current bug... When SD card is removed and replaced, stays in not detected loop... or something - myled = sdDetect; - myled2 = 0; + if(DEBUG) myled = sdDetect; + if(DEBUG) myled2 = 0; if(!sdDetect) { if(DEBUG) { @@ -228,9 +236,9 @@ wait_ms(50); } sdInsert = false; // Note no card is inserted - if(playlistExist){ + if(playlistExist){ // If a playlist has been made playlistExist = false; - deleteList(root); + deleteList(root); // Clear playlist curr = root; } lcd.cls(); @@ -298,52 +306,53 @@ } // ----------------- Press RPG Button ----------------- if(rpg.pb()) { - // if push button is pressed ... SOMETHING + // if push button is pressed: lcd.cls(); - lcd.printf("Song playing"); - - //Check sd card maybes - - // File location name thing + lcd.printf("Song playing"); // Inform user song is playing + + // File location name mySongName.erase(); - mySongName.append("/sd/"); - mySongName.append(curr->s_name); - mySongName.append(".wav"); - - // Open File + mySongName.append("/sd/"); // ======== Change if not using base sd card location ===== + mySongName.append(curr->s_name); // Add current song name + mySongName.append(".wav"); // Add .wav extension if(DEBUG) printf("Appended Name: %s\n\r", mySongName.c_str()); - wave_file=fopen(mySongName.c_str(),"r"); - wave_file_check(wave_array, wave_file); - if(DEBUG) printf("Sample Rate: %d\r\n", wave_file_info.samples_per_second); - fclose(wave_file); + // Wav file header info + wave_file=fopen(mySongName.c_str(),"r"); // Open file to get header information + wave_file_check(wave_array, wave_file); // Put info in global variable + if(DEBUG) printf("Sample Rate: %d\r\n", wave_file_info.samples_per_second); + fclose(wave_file); // Close file + // Initialize bottom row of LCD screen lcd.locate(0,1); lcd.printf("Time: / sec"); lcd.locate(10,1); + // Print length of selected wavfile lcd.printf("%d", (int)(wave_file_info.length_of_file / (wave_file_info.samples_per_second * wave_file_info.number_of_channels * wave_file_info.bytes_per_sample)) ); - + // Open song for playing wave_file=fopen(mySongName.c_str(),"r"); - + // Start Ticker function that counts time elapsed each second songTick.attach(&songClock, 1.0); + // Set reference time set_time(1357020000); time_i = time(NULL); - + // Play song if(DEBUG) printf("Start Song\r\n"); waver.play(wave_file); - + // Close file if(DEBUG) printf("Close Song!\r\n"); fclose(wave_file); + // End ticker function songTick.detach(); time_i = 0; + // Clear LCD and show selected wav file lcd.cls(); lcd.printf(curr->s_name); if(DEBUG) printf("Finished mai SONG!\r\n"); - } - if(DEBUG) printf("rpgTick: %d \r\n",rpgTick); + } } } }