1

Dependencies:   LCD4884 mbed

MP3.cpp

Committer:
nappy009
Date:
2016-12-05
Revision:
0:5d9ff41e32d2

File content as of revision 0:5d9ff41e32d2:

#include "mbed.h"
#include "LCD4884.h"
#include "string.h"
LCD4884 lcd;
Serial pc(SERIAL_TX,SERIAL_RX);
AnalogIn joy(A0);
char text1[50]={"MUSIC1"};
char text2[50]={"MUSIC2"};
char text3[50]={"MUSIC3"};
char text4[50]={"MUSIC4"};
int user(){        
    float i = joy.read()*1000;
        if(i>780 & i<785)  {return 10;} //none
        if(i<10)           {return 20;} //left
        if(i>760 & i<765)  {return 30;} //right
        if(i>950)          {return 40;} //up
        if(i>495 & i<505)  {return 50;} //down 
}
void page1(){                           //page to lcd
    lcd.LCD_write_string(30,0,"MENU",1);
    lcd.LCD_write_string(0,1,"USER1",0); //max14 6row            
    }
void page21(){
    lcd.LCD_write_string(30,0,"USER1",1);
    lcd.LCD_write_string(0,1,text1,1); //max14 6row            
    lcd.LCD_write_string(0,2,text2,0);
    lcd.LCD_write_string(0,3,text3,0);
    lcd.LCD_write_string(0,4,text4,0);
    }
void page22(){
    lcd.LCD_write_string(30,0,"USER1",1);
    lcd.LCD_write_string(0,1,text1,0); //max14 6row            
    lcd.LCD_write_string(0,2,text2,1);
    lcd.LCD_write_string(0,3,text3,0);
    lcd.LCD_write_string(0,4,text4,0);
    }
void page23(){
    lcd.LCD_write_string(30,0,"USER1",1);
    lcd.LCD_write_string(0,1,text1,0); //max14 6row            
    lcd.LCD_write_string(0,2,text2,0);
    lcd.LCD_write_string(0,3,text3,1);
    lcd.LCD_write_string(0,4,text4,0);
    }
void page24(){
    lcd.LCD_write_string(30,0,"USER1",1);
    lcd.LCD_write_string(0,1,text1,0); //max14 6row            
    lcd.LCD_write_string(0,2,text2,0);
    lcd.LCD_write_string(0,3,text3,0);
    lcd.LCD_write_string(0,4,text4,1);
    }        
void page31(){
    lcd.LCD_write_string(0,0,"NAME1",0);
    lcd.LCD_write_string(0,1,"ALBUM1",0); //max14 6row            
    lcd.LCD_write_string(0,2,"LIKE1",0);
    lcd.LCD_write_string(0,3,"MOOD1",0);
    lcd.LCD_write_string(0,4,"SKIP1",0);
    }
void page32(){
    lcd.LCD_write_string(0,0,"NAME2",0);
    lcd.LCD_write_string(0,1,"ALBUM2",0); //max14 6row            
    lcd.LCD_write_string(0,2,"LIKE2",0);
    lcd.LCD_write_string(0,3,"MOOD2",0);
    lcd.LCD_write_string(0,4,"SKIP2",0);
    }
void page33(){
    lcd.LCD_write_string(0,0,"NAME3",0);
    lcd.LCD_write_string(0,1,"ALBUM3",0); //max14 6row            
    lcd.LCD_write_string(0,2,"LIKE3",0);
    lcd.LCD_write_string(0,3,"MOOD3",0);
    lcd.LCD_write_string(0,4,"SKIP3",0);
    }
void page34(){
    lcd.LCD_write_string(0,0,"NAME4",0);
    lcd.LCD_write_string(0,1,"ALBUM4",0); //max14 6row            
    lcd.LCD_write_string(0,2,"LIKE4",0);
    lcd.LCD_write_string(0,3,"MOOD4",0);
    lcd.LCD_write_string(0,4,"SKIP4",0);
    }

int main() {
    lcd.LCD_init();
    lcd.backlight(ON);
    int change=0;
    int down=0;
    int num=0;
    while(1)
        {   
            num = user();       
            //page1();
            //printf("page1\n");
            switch(num){
            case 10:                    //main page
                lcd.LCD_clear();
                page1();
                printf("10\n");
                //printf("page1");
                wait(0.75);
                break;
            case 20:                    //left click//return main page
                lcd.LCD_clear();
                page1();
                printf("20\n");
//                printf("page11");
                wait(0.75);
                break;
            case 30:                    //next page1//next page2
                lcd.LCD_clear();
                printf("30\n");
                wait(0.75);
                change++;
                if(change==1){         //1 click//page2
                    page21();
                    printf("page21");
                    num = 50;
                    }
                if(change==2){          //2 click//page3
                    if(down==0){
                        page31();
                        printf("page31");
                        }
                    if(down==1){
                        page32();
                        printf("page32");
                        }
                    if(down==2){
                        page33();
                        printf("page33");
                        }
                    if(down==3){
                        page34();
                        printf("page34");
                        down=0;
                        } 
                    }
                if(change==3){          //reset change
                    change=1;
                    }    
                break;
            case 40:                    //click up
                lcd.LCD_clear();
                printf("40\n");
                wait(0.75);
                //if(down==1){
//                    page21();
//                    printf("page21");
//                    }
//                if(down==2){
//                    page22();
//                    printf("page22");
//                    down=1;
//                    }
//                if(down==3){
//                    page23();
//                    printf("page23");
//                    down=2;
//                    }
//                break;
            case 50:                    //click down 
                lcd.LCD_clear();
                printf("50\n");
                wait(0.75);
                down++;
                if(change==1){
                    if(down==0){
                        page21();
                        printf("page21");
                        }
                    if(down==1){
                        page22();
                        printf("page22");
                        }
                    if(down==2){
                        page23();
                        printf("page23");
                        }
                    if(down==3){
                        page24();
                        printf("page24");
                        }
                    if(down==4){
                        down=0;
                        }  
                   }
             }
      }
}