1

Dependencies:   LCD4884 mbed

Committer:
nappy009
Date:
Mon Dec 05 10:58:08 2016 +0000
Revision:
0:5d9ff41e32d2
1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nappy009 0:5d9ff41e32d2 1 #include "mbed.h"
nappy009 0:5d9ff41e32d2 2 #include "LCD4884.h"
nappy009 0:5d9ff41e32d2 3 #include "string.h"
nappy009 0:5d9ff41e32d2 4 LCD4884 lcd;
nappy009 0:5d9ff41e32d2 5 Serial pc(SERIAL_TX,SERIAL_RX);
nappy009 0:5d9ff41e32d2 6 AnalogIn joy(A0);
nappy009 0:5d9ff41e32d2 7 char text1[50]={"MUSIC1"};
nappy009 0:5d9ff41e32d2 8 char text2[50]={"MUSIC2"};
nappy009 0:5d9ff41e32d2 9 char text3[50]={"MUSIC3"};
nappy009 0:5d9ff41e32d2 10 char text4[50]={"MUSIC4"};
nappy009 0:5d9ff41e32d2 11 int user(){
nappy009 0:5d9ff41e32d2 12 float i = joy.read()*1000;
nappy009 0:5d9ff41e32d2 13 if(i>780 & i<785) {return 10;} //none
nappy009 0:5d9ff41e32d2 14 if(i<10) {return 20;} //left
nappy009 0:5d9ff41e32d2 15 if(i>760 & i<765) {return 30;} //right
nappy009 0:5d9ff41e32d2 16 if(i>950) {return 40;} //up
nappy009 0:5d9ff41e32d2 17 if(i>495 & i<505) {return 50;} //down
nappy009 0:5d9ff41e32d2 18 }
nappy009 0:5d9ff41e32d2 19 void page1(){ //page to lcd
nappy009 0:5d9ff41e32d2 20 lcd.LCD_write_string(30,0,"MENU",1);
nappy009 0:5d9ff41e32d2 21 lcd.LCD_write_string(0,1,"USER1",0); //max14 6row
nappy009 0:5d9ff41e32d2 22 }
nappy009 0:5d9ff41e32d2 23 void page21(){
nappy009 0:5d9ff41e32d2 24 lcd.LCD_write_string(30,0,"USER1",1);
nappy009 0:5d9ff41e32d2 25 lcd.LCD_write_string(0,1,text1,1); //max14 6row
nappy009 0:5d9ff41e32d2 26 lcd.LCD_write_string(0,2,text2,0);
nappy009 0:5d9ff41e32d2 27 lcd.LCD_write_string(0,3,text3,0);
nappy009 0:5d9ff41e32d2 28 lcd.LCD_write_string(0,4,text4,0);
nappy009 0:5d9ff41e32d2 29 }
nappy009 0:5d9ff41e32d2 30 void page22(){
nappy009 0:5d9ff41e32d2 31 lcd.LCD_write_string(30,0,"USER1",1);
nappy009 0:5d9ff41e32d2 32 lcd.LCD_write_string(0,1,text1,0); //max14 6row
nappy009 0:5d9ff41e32d2 33 lcd.LCD_write_string(0,2,text2,1);
nappy009 0:5d9ff41e32d2 34 lcd.LCD_write_string(0,3,text3,0);
nappy009 0:5d9ff41e32d2 35 lcd.LCD_write_string(0,4,text4,0);
nappy009 0:5d9ff41e32d2 36 }
nappy009 0:5d9ff41e32d2 37 void page23(){
nappy009 0:5d9ff41e32d2 38 lcd.LCD_write_string(30,0,"USER1",1);
nappy009 0:5d9ff41e32d2 39 lcd.LCD_write_string(0,1,text1,0); //max14 6row
nappy009 0:5d9ff41e32d2 40 lcd.LCD_write_string(0,2,text2,0);
nappy009 0:5d9ff41e32d2 41 lcd.LCD_write_string(0,3,text3,1);
nappy009 0:5d9ff41e32d2 42 lcd.LCD_write_string(0,4,text4,0);
nappy009 0:5d9ff41e32d2 43 }
nappy009 0:5d9ff41e32d2 44 void page24(){
nappy009 0:5d9ff41e32d2 45 lcd.LCD_write_string(30,0,"USER1",1);
nappy009 0:5d9ff41e32d2 46 lcd.LCD_write_string(0,1,text1,0); //max14 6row
nappy009 0:5d9ff41e32d2 47 lcd.LCD_write_string(0,2,text2,0);
nappy009 0:5d9ff41e32d2 48 lcd.LCD_write_string(0,3,text3,0);
nappy009 0:5d9ff41e32d2 49 lcd.LCD_write_string(0,4,text4,1);
nappy009 0:5d9ff41e32d2 50 }
nappy009 0:5d9ff41e32d2 51 void page31(){
nappy009 0:5d9ff41e32d2 52 lcd.LCD_write_string(0,0,"NAME1",0);
nappy009 0:5d9ff41e32d2 53 lcd.LCD_write_string(0,1,"ALBUM1",0); //max14 6row
nappy009 0:5d9ff41e32d2 54 lcd.LCD_write_string(0,2,"LIKE1",0);
nappy009 0:5d9ff41e32d2 55 lcd.LCD_write_string(0,3,"MOOD1",0);
nappy009 0:5d9ff41e32d2 56 lcd.LCD_write_string(0,4,"SKIP1",0);
nappy009 0:5d9ff41e32d2 57 }
nappy009 0:5d9ff41e32d2 58 void page32(){
nappy009 0:5d9ff41e32d2 59 lcd.LCD_write_string(0,0,"NAME2",0);
nappy009 0:5d9ff41e32d2 60 lcd.LCD_write_string(0,1,"ALBUM2",0); //max14 6row
nappy009 0:5d9ff41e32d2 61 lcd.LCD_write_string(0,2,"LIKE2",0);
nappy009 0:5d9ff41e32d2 62 lcd.LCD_write_string(0,3,"MOOD2",0);
nappy009 0:5d9ff41e32d2 63 lcd.LCD_write_string(0,4,"SKIP2",0);
nappy009 0:5d9ff41e32d2 64 }
nappy009 0:5d9ff41e32d2 65 void page33(){
nappy009 0:5d9ff41e32d2 66 lcd.LCD_write_string(0,0,"NAME3",0);
nappy009 0:5d9ff41e32d2 67 lcd.LCD_write_string(0,1,"ALBUM3",0); //max14 6row
nappy009 0:5d9ff41e32d2 68 lcd.LCD_write_string(0,2,"LIKE3",0);
nappy009 0:5d9ff41e32d2 69 lcd.LCD_write_string(0,3,"MOOD3",0);
nappy009 0:5d9ff41e32d2 70 lcd.LCD_write_string(0,4,"SKIP3",0);
nappy009 0:5d9ff41e32d2 71 }
nappy009 0:5d9ff41e32d2 72 void page34(){
nappy009 0:5d9ff41e32d2 73 lcd.LCD_write_string(0,0,"NAME4",0);
nappy009 0:5d9ff41e32d2 74 lcd.LCD_write_string(0,1,"ALBUM4",0); //max14 6row
nappy009 0:5d9ff41e32d2 75 lcd.LCD_write_string(0,2,"LIKE4",0);
nappy009 0:5d9ff41e32d2 76 lcd.LCD_write_string(0,3,"MOOD4",0);
nappy009 0:5d9ff41e32d2 77 lcd.LCD_write_string(0,4,"SKIP4",0);
nappy009 0:5d9ff41e32d2 78 }
nappy009 0:5d9ff41e32d2 79
nappy009 0:5d9ff41e32d2 80 int main() {
nappy009 0:5d9ff41e32d2 81 lcd.LCD_init();
nappy009 0:5d9ff41e32d2 82 lcd.backlight(ON);
nappy009 0:5d9ff41e32d2 83 int change=0;
nappy009 0:5d9ff41e32d2 84 int down=0;
nappy009 0:5d9ff41e32d2 85 int num=0;
nappy009 0:5d9ff41e32d2 86 while(1)
nappy009 0:5d9ff41e32d2 87 {
nappy009 0:5d9ff41e32d2 88 num = user();
nappy009 0:5d9ff41e32d2 89 //page1();
nappy009 0:5d9ff41e32d2 90 //printf("page1\n");
nappy009 0:5d9ff41e32d2 91 switch(num){
nappy009 0:5d9ff41e32d2 92 case 10: //main page
nappy009 0:5d9ff41e32d2 93 lcd.LCD_clear();
nappy009 0:5d9ff41e32d2 94 page1();
nappy009 0:5d9ff41e32d2 95 printf("10\n");
nappy009 0:5d9ff41e32d2 96 //printf("page1");
nappy009 0:5d9ff41e32d2 97 wait(0.75);
nappy009 0:5d9ff41e32d2 98 break;
nappy009 0:5d9ff41e32d2 99 case 20: //left click//return main page
nappy009 0:5d9ff41e32d2 100 lcd.LCD_clear();
nappy009 0:5d9ff41e32d2 101 page1();
nappy009 0:5d9ff41e32d2 102 printf("20\n");
nappy009 0:5d9ff41e32d2 103 // printf("page11");
nappy009 0:5d9ff41e32d2 104 wait(0.75);
nappy009 0:5d9ff41e32d2 105 break;
nappy009 0:5d9ff41e32d2 106 case 30: //next page1//next page2
nappy009 0:5d9ff41e32d2 107 lcd.LCD_clear();
nappy009 0:5d9ff41e32d2 108 printf("30\n");
nappy009 0:5d9ff41e32d2 109 wait(0.75);
nappy009 0:5d9ff41e32d2 110 change++;
nappy009 0:5d9ff41e32d2 111 if(change==1){ //1 click//page2
nappy009 0:5d9ff41e32d2 112 page21();
nappy009 0:5d9ff41e32d2 113 printf("page21");
nappy009 0:5d9ff41e32d2 114 num = 50;
nappy009 0:5d9ff41e32d2 115 }
nappy009 0:5d9ff41e32d2 116 if(change==2){ //2 click//page3
nappy009 0:5d9ff41e32d2 117 if(down==0){
nappy009 0:5d9ff41e32d2 118 page31();
nappy009 0:5d9ff41e32d2 119 printf("page31");
nappy009 0:5d9ff41e32d2 120 }
nappy009 0:5d9ff41e32d2 121 if(down==1){
nappy009 0:5d9ff41e32d2 122 page32();
nappy009 0:5d9ff41e32d2 123 printf("page32");
nappy009 0:5d9ff41e32d2 124 }
nappy009 0:5d9ff41e32d2 125 if(down==2){
nappy009 0:5d9ff41e32d2 126 page33();
nappy009 0:5d9ff41e32d2 127 printf("page33");
nappy009 0:5d9ff41e32d2 128 }
nappy009 0:5d9ff41e32d2 129 if(down==3){
nappy009 0:5d9ff41e32d2 130 page34();
nappy009 0:5d9ff41e32d2 131 printf("page34");
nappy009 0:5d9ff41e32d2 132 down=0;
nappy009 0:5d9ff41e32d2 133 }
nappy009 0:5d9ff41e32d2 134 }
nappy009 0:5d9ff41e32d2 135 if(change==3){ //reset change
nappy009 0:5d9ff41e32d2 136 change=1;
nappy009 0:5d9ff41e32d2 137 }
nappy009 0:5d9ff41e32d2 138 break;
nappy009 0:5d9ff41e32d2 139 case 40: //click up
nappy009 0:5d9ff41e32d2 140 lcd.LCD_clear();
nappy009 0:5d9ff41e32d2 141 printf("40\n");
nappy009 0:5d9ff41e32d2 142 wait(0.75);
nappy009 0:5d9ff41e32d2 143 //if(down==1){
nappy009 0:5d9ff41e32d2 144 // page21();
nappy009 0:5d9ff41e32d2 145 // printf("page21");
nappy009 0:5d9ff41e32d2 146 // }
nappy009 0:5d9ff41e32d2 147 // if(down==2){
nappy009 0:5d9ff41e32d2 148 // page22();
nappy009 0:5d9ff41e32d2 149 // printf("page22");
nappy009 0:5d9ff41e32d2 150 // down=1;
nappy009 0:5d9ff41e32d2 151 // }
nappy009 0:5d9ff41e32d2 152 // if(down==3){
nappy009 0:5d9ff41e32d2 153 // page23();
nappy009 0:5d9ff41e32d2 154 // printf("page23");
nappy009 0:5d9ff41e32d2 155 // down=2;
nappy009 0:5d9ff41e32d2 156 // }
nappy009 0:5d9ff41e32d2 157 // break;
nappy009 0:5d9ff41e32d2 158 case 50: //click down
nappy009 0:5d9ff41e32d2 159 lcd.LCD_clear();
nappy009 0:5d9ff41e32d2 160 printf("50\n");
nappy009 0:5d9ff41e32d2 161 wait(0.75);
nappy009 0:5d9ff41e32d2 162 down++;
nappy009 0:5d9ff41e32d2 163 if(change==1){
nappy009 0:5d9ff41e32d2 164 if(down==0){
nappy009 0:5d9ff41e32d2 165 page21();
nappy009 0:5d9ff41e32d2 166 printf("page21");
nappy009 0:5d9ff41e32d2 167 }
nappy009 0:5d9ff41e32d2 168 if(down==1){
nappy009 0:5d9ff41e32d2 169 page22();
nappy009 0:5d9ff41e32d2 170 printf("page22");
nappy009 0:5d9ff41e32d2 171 }
nappy009 0:5d9ff41e32d2 172 if(down==2){
nappy009 0:5d9ff41e32d2 173 page23();
nappy009 0:5d9ff41e32d2 174 printf("page23");
nappy009 0:5d9ff41e32d2 175 }
nappy009 0:5d9ff41e32d2 176 if(down==3){
nappy009 0:5d9ff41e32d2 177 page24();
nappy009 0:5d9ff41e32d2 178 printf("page24");
nappy009 0:5d9ff41e32d2 179 }
nappy009 0:5d9ff41e32d2 180 if(down==4){
nappy009 0:5d9ff41e32d2 181 down=0;
nappy009 0:5d9ff41e32d2 182 }
nappy009 0:5d9ff41e32d2 183 }
nappy009 0:5d9ff41e32d2 184 }
nappy009 0:5d9ff41e32d2 185 }
nappy009 0:5d9ff41e32d2 186 }