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