4180 project
Dependencies: 4DGL-uLCD-SE PinDetect SDFileSystem Speaker mbed wave_player
Fork of musicplayer by
Revision 2:54dcfef5c648, committed 2017-12-06
- Comitter:
- amaclean6
- Date:
- Wed Dec 06 08:51:00 2017 +0000
- Parent:
- 1:45d8f6557ff8
- Commit message:
- 1st
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL-uLCD-SE.lib Wed Dec 06 08:51:00 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
--- a/TextLCD.lib Mon Mar 17 18:48:13 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
--- a/main.cpp Mon Mar 17 18:48:13 2014 +0000 +++ b/main.cpp Wed Dec 06 08:51:00 2017 +0000 @@ -1,7 +1,7 @@ #include "mbed.h" #include "SDFileSystem.h" #include "wave_player.h" -#include "TextLCD.h" +#include "uLCD_4DGL.h" #include "PinDetect.h" #include "Speaker.h" #include <vector> @@ -16,19 +16,21 @@ using namespace std; SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card -TextLCD lcd(p9, p10, p11, p12, p13, p14); // rs, e, d4-d7 +uLCD_4DGL uLCD(p9,p10,p11); DigitalIn sdDetect(p17); // Set up a pin for SD Card Detect -PinDetect pb1(p28); // pb forup shift -PinDetect pb2(p29); // pb fordown shift -PinDetect pb3(p30); // pb for pause -PinDetect pb4(p27); // pb for volume or play +PinDetect pb1(p21); // pb forup shift +PinDetect pb2(p22); // pb fordown shift +PinDetect pb3(p23); // pb for pause + + AnalogOut DACout(p18); //set up speaker wave_player waver(&DACout); //set up wave player library int pos = 0; // index of the song -int vol = 0; // volume controller +int vol = 0; + bool playing = false; //variable for pause/play since we only have 1 pb for that vector<string> filenames; //filenames are stored in a vector string @@ -55,8 +57,8 @@ string songname = filenames[pos]; unsigned index = songname.find(".wav"); songname = songname.substr(0,index); - lcd.cls(); - lcd.printf(songname.c_str()); //it clears screen and then sets the new index song in the lcd display + uLCD.cls(); + uLCD.printf(songname.c_str()); //it clears screen and then sets the new index song in the uLCD display } //interrupt handler for pb2 void pb2_hit_callback (void) @@ -71,8 +73,8 @@ string songname = filenames[pos]; unsigned index = songname.find(".wav"); songname = songname.substr(0,index); - lcd.cls(); - lcd.printf(songname.c_str()); + uLCD.cls(); + uLCD.printf(songname.c_str()); } //interrupt handler for 3rd pushbutton void pb3_hit_callback (void) @@ -82,21 +84,15 @@ if (playing == false) { playing = true; } else if (playing == true) { - lcd.cls(); + uLCD.cls(); playing = false; string songname = filenames[pos]; unsigned index = songname.find(".wav"); songname = songname.substr(0,index); - lcd.printf(songname.c_str()); + uLCD.printf(songname.c_str()); } } -//interrupt handler for pb4 -void pb4_hit_callback (void){ - // this pb changes the volume by lowering the volume until it reaches 0. then it resets to the max volume - // the volume range has been divided into 16 possible ranges. and hence, it toggles through those 16 values - // this only changes the variable vol, which is then used in the wave player file to actually adjust the volume - vol = (vol+1) % 16; -} + int main() { @@ -107,39 +103,39 @@ pb1.mode(PullUp); pb2.mode(PullUp); pb3.mode(PullUp); - pb4.mode(PullUp); + //pb4.mode(PullUp); // Delay for initial pullup to take effect wait(.01); // Setup Interrupt callback functions for a pb hit pb1.attach_deasserted(&pb1_hit_callback); pb2.attach_deasserted(&pb2_hit_callback); pb3.attach_deasserted(&pb3_hit_callback); - pb4.attach_deasserted(&pb4_hit_callback); + // Start sampling pb inputs using interrupts pb1.setSampleFrequency(); pb2.setSampleFrequency(); pb3.setSampleFrequency(); - pb4.setSampleFrequency(); - lcd.cls(); + + uLCD.cls(); //detects whethere there is a SD card or not.. if not then it prints and informs the user while(sdDetect ==0) { - lcd.locate(0,0); - lcd.printf("Insert SD Card"); + uLCD.locate(0,0); + uLCD.printf("Insert SD Card"); wait(.5); } - lcd.cls(); + uLCD.cls(); wait(.5); sd.disk_initialize(); - read_file_names("/sd/Music"); + read_file_names("/sd/"); while(1) { //while pb3 is low, then we can start playing the song while(playing == true) { //we have 2 while loops..one while loop makes sure the music player is always on, the other one is for the song string songname = filenames[pos]; - string a = "/sd/Music/"; + string a = "/sd/"; string fname = a + songname; //retrieves the file name FILE *wave_file; - lcd.locate(0,1); - lcd.printf("Now Playing"); + uLCD.locate(0,4); + uLCD.printf("Now Playing"); wave_file = fopen(fname.c_str(),"r"); //opens the music file waver.play(wave_file); //plays the music file fclose(wave_file);