A S / Mbed 2 deprecated aos_mbed

Dependencies:   C12832_lcd EthernetInterface USBHost mbed-rtos mbed wave_player

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers player.cpp Source File

player.cpp

00001 /* FILE: player.cpp by Sidik Soleman
00002 */
00003 #include "player.h"
00004 
00005 C12832_LCD lcd;
00006 AnalogOut DACout(p18);
00007 /* joystick location */
00008 DigitalIn Up(p15);
00009 DigitalIn Down(p12);
00010 DigitalIn Left(p13);
00011 DigitalIn Right(p16);
00012 DigitalIn Play(p14);
00013 AnalogIn ain(p19);
00014 
00015 Ticker ticker;
00016 Ticker tickervolume;
00017 int joyup=0,joydown=0,joyplay=0;
00018 wave_player waver(&DACout);
00019 volatile int joyvalue=0;
00020 float aout = 0;
00021 FILE *wave_file;
00022 
00023 // Custom Function 
00024 void play(char* song){
00025     wave_file=fopen(song,"r");
00026     waver.play(wave_file);
00027     fclose(wave_file);
00028 }
00029 
00030 void welcome(){
00031    lcd.cls();
00032    lcd.locate(15,0);
00033    lcd.printf("MBED Player"); 
00034    Thread::wait(1);
00035    lcd.cls();
00036 }
00037 
00038 void print(vector<string> *listoffile, int current){
00039     lcd.cls();
00040     int nsong = listoffile->size();
00041     lcd.locate(0,0);
00042     lcd.printf("Song Title (%d/%d)",(current+1),nsong);
00043     lcd.locate(0,9);
00044     lcd.printf("-------------------------------");
00045     if (nsong == 0){
00046        lcd.locate(0,15);
00047        lcd.printf("No File Song");
00048     } else {
00049         lcd.printf("> %s",(listoffile->at(current)).c_str());
00050     }
00051 }
00052 
00053 /* JoyValue = 1: up, 2: down, 3: play */
00054 void joystickcontrol(){
00055     if (Up){
00056         if (joyup<NSAMPLE) joyup++;
00057         if (joyup==NSAMPLE){ joyvalue=1; joyup=0;}
00058     }
00059     if (Down){
00060         if (joydown<NSAMPLE) joydown++;
00061         if (joydown==NSAMPLE) { joyvalue=2; joydown = 0;}
00062     }
00063     if (Play){
00064         if (joyplay<NSAMPLE) joyplay++;
00065         if (joyplay==NSAMPLE) { joyvalue=3; joyplay=0;}
00066     }       
00067 }
00068 
00069 void controlvolume(){
00070     waver.volume = (float)ain;
00071 }