MP3 Player with touch panel interface and LCD display.
Dependencies: TextLCD mbed SDFileSystem
main.cpp
00001 /* Author: Pramod Nataraja & Vishnu Venkat */ 00002 00003 #include "mbed.h" 00004 #include "VS1002.h" 00005 #include "TextLCD.h" 00006 #include "mpr121.h" 00007 00008 VS1002 mp3(p5, p6, p7, p8,"sd",p11, p12 ,p13, p14, p23, p22, p21, p15); //Setup Audio decoder. Name is VS1002 even though VS1053 is used. 00009 TextLCD lcd1(p30, p29, p17, p18, p19, p20); //setup lcd 00010 InterruptIn interrupt(p26); // Create the interrupt receiver object on pin 26 00011 I2C i2c(p9, p10); // Setup the i2c bus on pins 9 and 10 00012 Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); //Setup Mpr121 00013 00014 /* Global Variables to store Status*/ 00015 int new_song_number=1; //Variable to store the Song Number 00016 int volume_set=-20; //Variable to store the Volume 00017 int previous_volume; //Variable to store the volume when muted 00018 bool pause=false; //Variable to store the status of Pause button 00019 bool mute=false; //Variable to store the status of mute button 00020 00021 int check=0; //Capacitative touch generates interrupt on both press and release. This variable tracks this and updates only on press. 00022 char *song_name[6]={"18 till I Die","Summer of 69","Boulevard", "Serenity","Crawling","In the end"}; //Array of song names entered manually 00023 00024 void fallInterrupt() 00025 { 00026 int key_code=0; 00027 int i=0; 00028 int value; 00029 value=mpr121.read(0x00); 00030 value +=mpr121.read(0x01)<<8; 00031 00032 i=0; 00033 if(check) 00034 check=0; 00035 else 00036 check=1; 00037 if(check) 00038 { 00039 for (i=0; i<12; i++) { 00040 if (((value>>i)&0x01)==1) key_code=i+1; //Convert value into decimal 00041 } 00042 00043 switch(key_code) // Different cases depending on key press 00044 { 00045 case 0:break; // Invalid entry . Valid 1-12 00046 case 1: 00047 case 2: 00048 case 3: 00049 case 4: 00050 case 5: 00051 case 6: new_song_number=key_code; // Play the selected song 00052 break; 00053 case 7:new_song_number+=1; // Next song 00054 if(new_song_number==7) 00055 new_song_number=1; 00056 break; 00057 case 8: new_song_number-=1; // Previous Song 00058 if(new_song_number==0) 00059 new_song_number=6; 00060 break; 00061 case 9: pause=!pause; // Pause/Play button 00062 break; 00063 case 10: volume_set+=3; // Volume Up 00064 if(volume_set>=0) 00065 volume_set=0; 00066 break; 00067 case 11: volume_set-=3; //Volume Down 00068 if(volume_set<-55) 00069 volume_set=-55; 00070 break; 00071 case 12: mute=!mute; //Mute/Unmute 00072 if(mute) 00073 { 00074 previous_volume=volume_set; // Attenuation of -55 db is small enough to not hear anything 00075 volume_set=-55; 00076 } 00077 else 00078 { 00079 volume_set=previous_volume; 00080 } 00081 break; 00082 default: lcd1.cls(); 00083 lcd1.printf("error"); // exit on error 00084 exit(1); 00085 } 00086 } 00087 /* Print to LCD the status of Song */ 00088 lcd1.cls(); 00089 if(pause) 00090 lcd1.printf("Paused "); 00091 if(mute) 00092 lcd1.printf("Muted"); 00093 if(!mute && !pause) 00094 lcd1.printf("Playing"); 00095 lcd1.printf("\n %d %s",new_song_number,song_name[new_song_number-1]); 00096 00097 } 00098 00099 int main () 00100 { 00101 /*============================================================ 00102 * MP3 Initialising 00103 *==========================================================*/ 00104 00105 mp3._RST = 1; 00106 mp3.cs_high(); //chip disabled 00107 mp3.sci_initialise(); //initialise MBED 00108 mp3.sci_write(0x00,(SM_SDINEW+SM_STREAM+SM_DIFF)); 00109 mp3.sci_write(0x03, 0x9800); 00110 mp3.sdi_initialise(); 00111 00112 00113 /* Touch Pad setup */ 00114 interrupt.fall(&fallInterrupt); 00115 interrupt.mode(PullUp); 00116 00117 while(1) 00118 { 00119 mp3.play_song(new_song_number); 00120 } 00121 00122 } 00123 00124
Generated on Wed Jul 13 2022 20:51:16 by 1.7.2