![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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
main.cpp@0:9cb0b3d1b9e6, 2010-10-12 (annotated)
- Committer:
- mpetersen3
- Date:
- Tue Oct 12 21:25:35 2010 +0000
- Revision:
- 0:9cb0b3d1b9e6
This revision adds a user interface for the mp3 player
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mpetersen3 | 0:9cb0b3d1b9e6 | 1 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 2 | #include "mbed.h" |
mpetersen3 | 0:9cb0b3d1b9e6 | 3 | #include "VS1002.h" |
mpetersen3 | 0:9cb0b3d1b9e6 | 4 | #include "TextLCD.h" |
mpetersen3 | 0:9cb0b3d1b9e6 | 5 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 6 | TextLCD lcd2(p10, p18, p24, p23, p22, p21, TextLCD::LCD16x2 ); // rs, e, d0-d3 |
mpetersen3 | 0:9cb0b3d1b9e6 | 7 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 8 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 9 | /* |
mpetersen3 | 0:9cb0b3d1b9e6 | 10 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 11 | Arduino MP3 Shield MP3Player_UI |
mpetersen3 | 0:9cb0b3d1b9e6 | 12 | 2010/10/10 |
mpetersen3 | 0:9cb0b3d1b9e6 | 13 | This program comes from http://mbed.org/cookbook/VS1002-MP3-Decoder and is the work of xshige. |
mpetersen3 | 0:9cb0b3d1b9e6 | 14 | (Very small modification done to fit latest libs) |
mpetersen3 | 0:9cb0b3d1b9e6 | 15 | **more small modifications done to add a small user interface via LCD screen, rotary encoder and dipswitch, |
mpetersen3 | 0:9cb0b3d1b9e6 | 16 | see http://mbed.org/cookbook/MP3-Player for more information on pinout for these devices, these UI mods by (mpetersen3 and kbuck3) |
mpetersen3 | 0:9cb0b3d1b9e6 | 17 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 18 | Pin Assigenment for Arduino MP3 Shield |
mpetersen3 | 0:9cb0b3d1b9e6 | 19 | (VS1053 employed, issued by sparkfun.com) |
mpetersen3 | 0:9cb0b3d1b9e6 | 20 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 21 | MP3 Sheild Side | mbed Side |
mpetersen3 | 0:9cb0b3d1b9e6 | 22 | --------------------------------------- |
mpetersen3 | 0:9cb0b3d1b9e6 | 23 | D2(BSYNC)------------17 |
mpetersen3 | 0:9cb0b3d1b9e6 | 24 | D3(DREQ)-------------16 |
mpetersen3 | 0:9cb0b3d1b9e6 | 25 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 26 | D9(CS)---------------14 |
mpetersen3 | 0:9cb0b3d1b9e6 | 27 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 28 | D11(MOSI)------------5 |
mpetersen3 | 0:9cb0b3d1b9e6 | 29 | D12(MISO)------------6 |
mpetersen3 | 0:9cb0b3d1b9e6 | 30 | D13(SCK)-------------7 |
mpetersen3 | 0:9cb0b3d1b9e6 | 31 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 32 | GND------------------GND(1) |
mpetersen3 | 0:9cb0b3d1b9e6 | 33 | 5V-------------------VU(39) |
mpetersen3 | 0:9cb0b3d1b9e6 | 34 | RESET----------------15 |
mpetersen3 | 0:9cb0b3d1b9e6 | 35 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 36 | Volume will not used. (pin20 will not used) |
mpetersen3 | 0:9cb0b3d1b9e6 | 37 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 38 | */ |
mpetersen3 | 0:9cb0b3d1b9e6 | 39 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 40 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 41 | //PinName mmosi, PinName mmiso, PinName ssck, PinName ccs, const char *name, |
mpetersen3 | 0:9cb0b3d1b9e6 | 42 | // PinName mosi, PinName miso, PinName sck, PinName cs, PinName rst, |
mpetersen3 | 0:9cb0b3d1b9e6 | 43 | // PinName dreq, PinName dcs, PinName vol) |
mpetersen3 | 0:9cb0b3d1b9e6 | 44 | VS1002 mp3(p11, p12, p13, p8, "sd", |
mpetersen3 | 0:9cb0b3d1b9e6 | 45 | p5, p6, p7, p14, p15, |
mpetersen3 | 0:9cb0b3d1b9e6 | 46 | p16, p17, p20); //p14 in BoB non-functional so replace with p18 |
mpetersen3 | 0:9cb0b3d1b9e6 | 47 | AnalogIn rotary(p19); |
mpetersen3 | 0:9cb0b3d1b9e6 | 48 | DigitalIn pause(p28); |
mpetersen3 | 0:9cb0b3d1b9e6 | 49 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 50 | int main () { |
mpetersen3 | 0:9cb0b3d1b9e6 | 51 | // make debug port Fast |
mpetersen3 | 0:9cb0b3d1b9e6 | 52 | Serial pc(USBTX, USBRX); |
mpetersen3 | 0:9cb0b3d1b9e6 | 53 | pc.baud(9600); |
mpetersen3 | 0:9cb0b3d1b9e6 | 54 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 55 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 56 | // pc.baud(115200); |
mpetersen3 | 0:9cb0b3d1b9e6 | 57 | // pc.baud(230400); |
mpetersen3 | 0:9cb0b3d1b9e6 | 58 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 59 | /*============================================================ |
mpetersen3 | 0:9cb0b3d1b9e6 | 60 | * MP3 Initialising |
mpetersen3 | 0:9cb0b3d1b9e6 | 61 | *==========================================================*/ |
mpetersen3 | 0:9cb0b3d1b9e6 | 62 | #ifndef FS_ONLY |
mpetersen3 | 0:9cb0b3d1b9e6 | 63 | mp3._RST = 1; |
mpetersen3 | 0:9cb0b3d1b9e6 | 64 | mp3.cs_high(); //chip disabled |
mpetersen3 | 0:9cb0b3d1b9e6 | 65 | mp3.sci_initialise(); //initialise MBED |
mpetersen3 | 0:9cb0b3d1b9e6 | 66 | mp3.sci_write(0x00,(SM_SDINEW+SM_STREAM+SM_DIFF)); |
mpetersen3 | 0:9cb0b3d1b9e6 | 67 | mp3.sci_write(0x03, 0x9800); |
mpetersen3 | 0:9cb0b3d1b9e6 | 68 | mp3.sdi_initialise(); |
mpetersen3 | 0:9cb0b3d1b9e6 | 69 | #endif |
mpetersen3 | 0:9cb0b3d1b9e6 | 70 | /*============================================================ |
mpetersen3 | 0:9cb0b3d1b9e6 | 71 | * This is the good part |
mpetersen3 | 0:9cb0b3d1b9e6 | 72 | *==========================================================*/ |
mpetersen3 | 0:9cb0b3d1b9e6 | 73 | int a=0; |
mpetersen3 | 0:9cb0b3d1b9e6 | 74 | printf("%i\n",a); |
mpetersen3 | 0:9cb0b3d1b9e6 | 75 | while (true) { |
mpetersen3 | 0:9cb0b3d1b9e6 | 76 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 77 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 78 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 79 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 80 | mp3.play_song(a); |
mpetersen3 | 0:9cb0b3d1b9e6 | 81 | a++; |
mpetersen3 | 0:9cb0b3d1b9e6 | 82 | wait(1); |
mpetersen3 | 0:9cb0b3d1b9e6 | 83 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 84 | if (pause) { |
mpetersen3 | 0:9cb0b3d1b9e6 | 85 | while (pause) { |
mpetersen3 | 0:9cb0b3d1b9e6 | 86 | // shows you which song number you have chosen using the rotary dial |
mpetersen3 | 0:9cb0b3d1b9e6 | 87 | lcd2.printf("You have chosen the %i song\n",a); |
mpetersen3 | 0:9cb0b3d1b9e6 | 88 | if ((rotary>0)&&(rotary<=0.1)) { |
mpetersen3 | 0:9cb0b3d1b9e6 | 89 | a=1; |
mpetersen3 | 0:9cb0b3d1b9e6 | 90 | |
mpetersen3 | 0:9cb0b3d1b9e6 | 91 | } else if ((rotary>0.1)&&(rotary<=0.2)) { |
mpetersen3 | 0:9cb0b3d1b9e6 | 92 | a=2; |
mpetersen3 | 0:9cb0b3d1b9e6 | 93 | } else if ((rotary>0.2)&&(rotary<=0.3)) { |
mpetersen3 | 0:9cb0b3d1b9e6 | 94 | a=3; |
mpetersen3 | 0:9cb0b3d1b9e6 | 95 | } else if ((rotary>0.3)&&(rotary<=0.4)) { |
mpetersen3 | 0:9cb0b3d1b9e6 | 96 | a=4; |
mpetersen3 | 0:9cb0b3d1b9e6 | 97 | } else if ((rotary>0.4)&&(rotary<=0.5)) { |
mpetersen3 | 0:9cb0b3d1b9e6 | 98 | a=5; |
mpetersen3 | 0:9cb0b3d1b9e6 | 99 | } else if ((rotary>0.5)&&(rotary<=0.6)) { |
mpetersen3 | 0:9cb0b3d1b9e6 | 100 | a=6; |
mpetersen3 | 0:9cb0b3d1b9e6 | 101 | } else if ((rotary>0.6)&&(rotary<=0.7)) { |
mpetersen3 | 0:9cb0b3d1b9e6 | 102 | a=7; |
mpetersen3 | 0:9cb0b3d1b9e6 | 103 | } else if ((rotary>0.7)&&(rotary<=0.8)) { |
mpetersen3 | 0:9cb0b3d1b9e6 | 104 | a=8; |
mpetersen3 | 0:9cb0b3d1b9e6 | 105 | } else if ((rotary>0.8)&&(rotary<=0.9)) { |
mpetersen3 | 0:9cb0b3d1b9e6 | 106 | a=9; |
mpetersen3 | 0:9cb0b3d1b9e6 | 107 | } else if ((rotary>0.9)&&(rotary<=1.0)) { |
mpetersen3 | 0:9cb0b3d1b9e6 | 108 | a=10; |
mpetersen3 | 0:9cb0b3d1b9e6 | 109 | } |
mpetersen3 | 0:9cb0b3d1b9e6 | 110 | } |
mpetersen3 | 0:9cb0b3d1b9e6 | 111 | } |
mpetersen3 | 0:9cb0b3d1b9e6 | 112 | } |
mpetersen3 | 0:9cb0b3d1b9e6 | 113 | printf("Done.\r\n"); |
mpetersen3 | 0:9cb0b3d1b9e6 | 114 | } |