MP3 PLAYER
Dependencies: DebouncedInterrupt SDFileSystem SPI_TFT_ILI9341 ST_401_84MHZ TFT_fonts VS1053 mbed
Fork of B18_MP3_PLAYER by
main.cpp@0:f7d37719bcfc, 2015-12-07 (annotated)
- Committer:
- PKnevermind
- Date:
- Mon Dec 07 10:21:01 2015 +0000
- Revision:
- 0:f7d37719bcfc
- Child:
- 1:28ecafb2b832
scscsa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PKnevermind | 0:f7d37719bcfc | 1 | #include "mbed.h" |
PKnevermind | 0:f7d37719bcfc | 2 | #include "player.h" |
PKnevermind | 0:f7d37719bcfc | 3 | |
PKnevermind | 0:f7d37719bcfc | 4 | |
PKnevermind | 0:f7d37719bcfc | 5 | /*InterruptIn KEY_PS(D5); //Play/Stop/Recording |
PKnevermind | 0:f7d37719bcfc | 6 | InterruptIn KEY_Pre(D6); //Previous |
PKnevermind | 0:f7d37719bcfc | 7 | InterruptIn KEY_Next(D4); //Next |
PKnevermind | 0:f7d37719bcfc | 8 | InterruptIn KEY_Up(D3); //Volume up |
PKnevermind | 0:f7d37719bcfc | 9 | InterruptIn KEY_Down(D7); //Volume dowm*/ |
PKnevermind | 0:f7d37719bcfc | 10 | |
PKnevermind | 0:f7d37719bcfc | 11 | DigitalOut MyLED(D8); //LED |
PKnevermind | 0:f7d37719bcfc | 12 | |
PKnevermind | 0:f7d37719bcfc | 13 | Player player; |
PKnevermind | 0:f7d37719bcfc | 14 | Ticker t; |
PKnevermind | 0:f7d37719bcfc | 15 | Timer timer; |
PKnevermind | 0:f7d37719bcfc | 16 | |
PKnevermind | 0:f7d37719bcfc | 17 | extern char list[20][50]; //song list |
PKnevermind | 0:f7d37719bcfc | 18 | extern unsigned char vlume; //vlume |
PKnevermind | 0:f7d37719bcfc | 19 | extern unsigned char vlumeflag; //set vlume flag |
PKnevermind | 0:f7d37719bcfc | 20 | extern char index; //song play index |
PKnevermind | 0:f7d37719bcfc | 21 | extern char index_MAX; //how many song in all |
PKnevermind | 0:f7d37719bcfc | 22 | extern playerStatetype playerState; |
PKnevermind | 0:f7d37719bcfc | 23 | |
PKnevermind | 0:f7d37719bcfc | 24 | int falltime; |
PKnevermind | 0:f7d37719bcfc | 25 | |
PKnevermind | 0:f7d37719bcfc | 26 | /*void LEDflip() |
PKnevermind | 0:f7d37719bcfc | 27 | { |
PKnevermind | 0:f7d37719bcfc | 28 | if (playerState == PS_PAUSE) MyLED = 0; |
PKnevermind | 0:f7d37719bcfc | 29 | else if (playerState == PS_STOP) MyLED = 0; |
PKnevermind | 0:f7d37719bcfc | 30 | else MyLED = !MyLED; |
PKnevermind | 0:f7d37719bcfc | 31 | } |
PKnevermind | 0:f7d37719bcfc | 32 | |
PKnevermind | 0:f7d37719bcfc | 33 | void fallFlip() |
PKnevermind | 0:f7d37719bcfc | 34 | { |
PKnevermind | 0:f7d37719bcfc | 35 | falltime=timer.read_ms(); |
PKnevermind | 0:f7d37719bcfc | 36 | } |
PKnevermind | 0:f7d37719bcfc | 37 | |
PKnevermind | 0:f7d37719bcfc | 38 | void riseFlip() |
PKnevermind | 0:f7d37719bcfc | 39 | { |
PKnevermind | 0:f7d37719bcfc | 40 | if((timer.read_ms()-falltime)>1000) //1s |
PKnevermind | 0:f7d37719bcfc | 41 | { |
PKnevermind | 0:f7d37719bcfc | 42 | playerState = PS_RECORDING; //long press for recording |
PKnevermind | 0:f7d37719bcfc | 43 | } |
PKnevermind | 0:f7d37719bcfc | 44 | else |
PKnevermind | 0:f7d37719bcfc | 45 | { |
PKnevermind | 0:f7d37719bcfc | 46 | if(playerState == PS_PAUSE)playerState = PS_PLAY; //play or pause |
PKnevermind | 0:f7d37719bcfc | 47 | else playerState = PS_PAUSE; |
PKnevermind | 0:f7d37719bcfc | 48 | } |
PKnevermind | 0:f7d37719bcfc | 49 | } |
PKnevermind | 0:f7d37719bcfc | 50 | |
PKnevermind | 0:f7d37719bcfc | 51 | |
PKnevermind | 0:f7d37719bcfc | 52 | void VolumeFlip() |
PKnevermind | 0:f7d37719bcfc | 53 | { |
PKnevermind | 0:f7d37719bcfc | 54 | if(KEY_Up == 0) |
PKnevermind | 0:f7d37719bcfc | 55 | { |
PKnevermind | 0:f7d37719bcfc | 56 | vlume = (vlume-0x10 >= 0)?vlume-0x10:vlume; |
PKnevermind | 0:f7d37719bcfc | 57 | } |
PKnevermind | 0:f7d37719bcfc | 58 | |
PKnevermind | 0:f7d37719bcfc | 59 | if(KEY_Down == 0) |
PKnevermind | 0:f7d37719bcfc | 60 | { |
PKnevermind | 0:f7d37719bcfc | 61 | vlume = (vlume+0x10<0xA0)?vlume+0x10:vlume; |
PKnevermind | 0:f7d37719bcfc | 62 | } |
PKnevermind | 0:f7d37719bcfc | 63 | printf("vlume : %d\r\n",10-vlume/0x10); |
PKnevermind | 0:f7d37719bcfc | 64 | vlumeflag = 1; |
PKnevermind | 0:f7d37719bcfc | 65 | } |
PKnevermind | 0:f7d37719bcfc | 66 | |
PKnevermind | 0:f7d37719bcfc | 67 | |
PKnevermind | 0:f7d37719bcfc | 68 | void Pre_Next() |
PKnevermind | 0:f7d37719bcfc | 69 | { |
PKnevermind | 0:f7d37719bcfc | 70 | if(KEY_Next == 0) |
PKnevermind | 0:f7d37719bcfc | 71 | { |
PKnevermind | 0:f7d37719bcfc | 72 | index = (index+1 > index_MAX)?0:index+1; |
PKnevermind | 0:f7d37719bcfc | 73 | } |
PKnevermind | 0:f7d37719bcfc | 74 | |
PKnevermind | 0:f7d37719bcfc | 75 | if(KEY_Pre == 0) |
PKnevermind | 0:f7d37719bcfc | 76 | { |
PKnevermind | 0:f7d37719bcfc | 77 | index = (index-1 < 0)?index_MAX:index-1; |
PKnevermind | 0:f7d37719bcfc | 78 | } |
PKnevermind | 0:f7d37719bcfc | 79 | playerState = PS_STOP; |
PKnevermind | 0:f7d37719bcfc | 80 | }*/ |
PKnevermind | 0:f7d37719bcfc | 81 | |
PKnevermind | 0:f7d37719bcfc | 82 | int main() { |
PKnevermind | 0:f7d37719bcfc | 83 | |
PKnevermind | 0:f7d37719bcfc | 84 | /*KEY_PS.fall(&fallFlip); |
PKnevermind | 0:f7d37719bcfc | 85 | KEY_PS.rise(&riseFlip); |
PKnevermind | 0:f7d37719bcfc | 86 | KEY_Up.fall(&VolumeFlip); |
PKnevermind | 0:f7d37719bcfc | 87 | KEY_Down.fall(&VolumeFlip); |
PKnevermind | 0:f7d37719bcfc | 88 | KEY_Pre.fall(&Pre_Next); |
PKnevermind | 0:f7d37719bcfc | 89 | KEY_Next.fall(&Pre_Next); |
PKnevermind | 0:f7d37719bcfc | 90 | t.attach(&LEDflip,0.5);*/ |
PKnevermind | 0:f7d37719bcfc | 91 | |
PKnevermind | 0:f7d37719bcfc | 92 | player.begin(); |
PKnevermind | 0:f7d37719bcfc | 93 | timer.start(); |
PKnevermind | 0:f7d37719bcfc | 94 | |
PKnevermind | 0:f7d37719bcfc | 95 | while(1) |
PKnevermind | 0:f7d37719bcfc | 96 | { |
PKnevermind | 0:f7d37719bcfc | 97 | player.playFile(list[index]); |
PKnevermind | 0:f7d37719bcfc | 98 | } |
PKnevermind | 0:f7d37719bcfc | 99 | |
PKnevermind | 0:f7d37719bcfc | 100 | } |
PKnevermind | 0:f7d37719bcfc | 101 |