Arduino MP3 Shield MP3Player This program comes from http://mbed.org/cookbook/VS1002-MP3-Decoder (Very small modification done to fit latest libs) **Additional small mods to xshige\'s code by mpetersen3 and kbuck3 to add a user interface

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 #include "mbed.h"
00003 #include "VS1002.h"
00004 #include "TextLCD.h"
00005 
00006 TextLCD lcd2(p10, p18, p24, p23, p22, p21, TextLCD::LCD16x2 ); // rs, e, d0-d3
00007 
00008 
00009 /*
00010 
00011  Arduino MP3 Shield MP3Player_UI
00012  2010/10/10
00013  This program comes from http://mbed.org/cookbook/VS1002-MP3-Decoder and is the work of xshige.
00014  (Very small modification done to fit latest libs)
00015 **more small modifications done to add a small user interface via LCD screen, rotary encoder and dipswitch,
00016 see http://mbed.org/cookbook/MP3-Player for more information on pinout for these devices, these UI mods by (mpetersen3 and kbuck3)
00017 
00018  Pin Assigenment for Arduino MP3 Shield
00019  (VS1053 employed, issued by sparkfun.com)
00020 
00021  MP3 Sheild Side   |  mbed Side
00022  ---------------------------------------
00023   D2(BSYNC)------------17
00024   D3(DREQ)-------------16
00025 
00026   D9(CS)---------------14
00027 
00028   D11(MOSI)------------5
00029   D12(MISO)------------6
00030   D13(SCK)-------------7
00031 
00032   GND------------------GND(1)
00033   5V-------------------VU(39)
00034   RESET----------------15
00035 
00036  Volume will not used. (pin20 will not used)
00037 
00038 */
00039 
00040 
00041 //PinName mmosi, PinName mmiso, PinName ssck, PinName ccs, const char *name,
00042 //         PinName mosi, PinName miso, PinName sck, PinName cs, PinName rst,
00043 //         PinName dreq, PinName dcs, PinName vol)
00044 VS1002 mp3(p11, p12, p13, p8, "sd",
00045            p5, p6, p7, p14, p15,
00046            p16, p17, p20);     //p14 in BoB non-functional so replace with p18
00047 AnalogIn rotary(p19);
00048 DigitalIn pause(p28);
00049 
00050 int main () {
00051     // make debug port Fast
00052     Serial pc(USBTX, USBRX);
00053     pc.baud(9600);
00054 
00055 
00056     // pc.baud(115200);
00057 //  pc.baud(230400);
00058 
00059     /*============================================================
00060      * MP3 Initialising
00061      *==========================================================*/
00062 #ifndef FS_ONLY
00063     mp3._RST = 1;
00064     mp3.cs_high();                                   //chip disabled
00065     mp3.sci_initialise();                            //initialise MBED
00066     mp3.sci_write(0x00,(SM_SDINEW+SM_STREAM+SM_DIFF));
00067     mp3.sci_write(0x03, 0x9800);
00068     mp3.sdi_initialise();
00069 #endif
00070     /*============================================================
00071      * This is the good part
00072      *==========================================================*/
00073     int a=0;
00074     printf("%i\n",a);
00075     while (true) {
00076 
00077         
00078 
00079         
00080         mp3.play_song(a);
00081         a++;
00082         wait(1);
00083         
00084         if (pause) {
00085             while (pause) {
00086                 // shows you which song number you have chosen using the rotary dial
00087                 lcd2.printf("You have chosen the %i song\n",a);
00088                 if ((rotary>0)&&(rotary<=0.1)) {
00089                     a=1;
00090 
00091                 } else if ((rotary>0.1)&&(rotary<=0.2)) {
00092                     a=2;
00093                 } else if ((rotary>0.2)&&(rotary<=0.3)) {
00094                     a=3;
00095                 } else if ((rotary>0.3)&&(rotary<=0.4)) {
00096                     a=4;
00097                 } else if ((rotary>0.4)&&(rotary<=0.5)) {
00098                     a=5;
00099                 } else if ((rotary>0.5)&&(rotary<=0.6)) {
00100                     a=6;
00101                 } else if ((rotary>0.6)&&(rotary<=0.7)) {
00102                     a=7;
00103                 } else if ((rotary>0.7)&&(rotary<=0.8)) {
00104                     a=8;
00105                 } else if ((rotary>0.8)&&(rotary<=0.9)) {
00106                     a=9;
00107                 } else if ((rotary>0.9)&&(rotary<=1.0)) {
00108                     a=10;
00109                 }
00110             }
00111             }
00112         }
00113         printf("Done.\r\n");
00114     }