Aussawin Wutti
/
LCD4884-FRA-project
menu LCD4884 locker
Fork of LCD4884 by
Diff: main.cpp
- Revision:
- 1:452282f5895f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Dec 10 06:11:35 2017 +0000 @@ -0,0 +1,359 @@ +#include "mbed.h" +#include "LCD4884.h" + +AnalogIn input(A0); +LCD4884 show; +float analong_data; +int state_menu =0; + +void menu(); +void menu_status(); +void menu_RFID(); +void menu_pass(); +void menu_register(); + +int main(){ + char buttom[10]; + show.LCD_init(); + while(1){ + analong_data = input.read(); + sprintf(buttom, "%.3f", analong_data); + show.backlight(0); + + if(state_menu == 0){ + show.LCD_write_string( 36, 0,"<Hello>", MENU_NORMAL); + show.LCD_write_string( 0, 0,buttom, MENU_NORMAL); + wait(0.2); + menu(); + }else if(state_menu == 1){ + show.LCD_write_string( 0, 1,buttom, MENU_NORMAL); wait(0.2); + menu_status(); + }else if(state_menu == 2){ + show.LCD_write_string( 0, 1,buttom, MENU_NORMAL); wait(0.2); + menu_RFID(); + }else if(state_menu == 3){ + show.LCD_write_string( 0, 1,buttom, MENU_NORMAL); wait(0.2); + menu_pass(); + }else if(state_menu == 4){ + show.LCD_write_string( 0, 1,buttom, MENU_NORMAL); wait(0.2); + menu_register(); + }else{ + show.LCD_clear(); + } + } +} + +int HL[4]={0,0,0,0}; //MENU_NORMAL 0 //MENU_HIGHLIGHT 1 // ประกาศไว้แบบ globeเพราะถ้าอยู่ใน while(1)มันจะรีเซ็ตทุกครั้ง +int count_menu =0; +float test; + +void menu(){ +////////////////////////////5 menu in one function //////////////////////////////////////// + if(analong_data>0.98){ + count_menu -= 1; + }else if(analong_data<0.55 && analong_data>0.3){ + count_menu += 1; + } + + if(count_menu == 1){ + HL[0] = 1; HL[1] = 0; HL[2] = 0; HL[3] = 0; + } + if(count_menu == 2){ + HL[0] = 0; HL[1] = 1; HL[2] = 0; HL[3] = 0; + } + if(count_menu == 3){ + HL[0] = 0; HL[1] = 0; HL[2] = 1; HL[3] = 0; + } + if(count_menu == 4){ + HL[0] = 0; HL[1] = 0; HL[2] = 0; HL[3] = 1; + } + if(count_menu ==-1){ + count_menu = 0; + } + if(count_menu ==5){ + count_menu = 4; + } +/////////////////////////////Hightlight //////////////////////////////////////////// + show.LCD_write_string( 0, 2, "1.Status Lock-", HL[0]); + show.LCD_write_string( 0, 3, "2.Open by RFID", HL[1]); + show.LCD_write_string( 0, 4, "3.Open by pass", HL[2]); + show.LCD_write_string( 0, 5, "4.Register", HL[3]); + +//////////////////////////call new function (branch menu)//////////////////////////// + if(HL[0]==1 ){ + if(analong_data>0.15 && analong_data<0.3){ + show.LCD_clear(); + count_menu = 0; //Status + state_menu =1; + } + } + if(HL[1]==1 ){ + if(analong_data>0.15 && analong_data<0.3){ + show.LCD_clear(); + count_menu = 0; //Open by RFID + state_menu =2; + } + } + if(HL[2]==1 ){ + if(analong_data>0.15 && analong_data<0.3){ + show.LCD_clear(); + count_menu = 0; //Open by pass + state_menu =3; + } + } + if(HL[3]==1 ){ + if(analong_data>0.15 && analong_data<0.3){ + show.LCD_clear(); + count_menu = 0; //Register + state_menu =4; + } + } +} + +int h_s=0; +int h_s1 =0; +void menu_status(){ + if(analong_data>0.98){ + count_menu -= 1; + }else if(analong_data<0.55 && analong_data>0.3){ + count_menu += 1; + } + + if(count_menu == 1){ + h_s=1; + } + else if(count_menu == 0){ + h_s=0; + }else{ + count_menu = 0; + } + show.LCD_write_string( 0, 0,"Status-Locker", MENU_NORMAL); + show.LCD_write_string( 0, 5,"<Back", h_s); + + if(h_s == 1 ){ + if(analong_data>0.15 && analong_data<0.3){ + show.LCD_clear(); + state_menu =0; + } + } + +} + +void menu_RFID(){ + if(analong_data>0.98){ + count_menu -= 1; + }else if(analong_data<0.55 && analong_data>0.3){ + count_menu += 1; + } + + if(count_menu == 1){ + h_s=1; + } + else if(count_menu == 0){ + h_s=0; + }else{ + count_menu = 0; + } + show.LCD_write_string( 0, 0,"Open-RFID", MENU_NORMAL); + show.LCD_write_string( 0, 5,"<Back", h_s); + + if(h_s == 1 ){ + if(analong_data>0.15 && analong_data<0.3){ + show.LCD_clear(); + state_menu =0; + } + } +} +int HL1[6]={0,0,0,0,0,0}; //MENU_NORMAL 0 //MENU_HIGHLIGHT 1 // ประกาศไว้แบบ globeเพราะถ้าอยู่ใน while(1)มันจะรีเซ็ตทุกครั้ง +char pass1[2]="0"; char pass2[2]="0"; char pass3[2]="0"; char pass4[2]="0"; char pass5[2]="0"; char pass6[2]="0"; + +int num1 = 0; int num2 = 0; int num3 = 0; int num4 = 0; int num5 = 0; int num6 = 0; + +void menu_pass(){ + if(analong_data<0.1){ + count_menu -= 1; + }else if(analong_data<0.75 && analong_data>0.70){ + count_menu += 1; + } + + + if(count_menu ==0){ + HL1[0] = 1; HL1[1] = 0; HL1[2] = 0; HL1[3] = 0; HL1[4] = 0; HL1[5] = 0; + h_s1=0; h_s =0; + } + if(count_menu == 1){ + HL1[0] = 0; HL1[1] = 1; HL1[2] = 0; HL1[3] = 0; HL1[4] = 0; HL1[5] = 0; + h_s1=0; h_s =0; + } + if(count_menu == 2){ + HL1[0] = 0; HL1[1] = 0; HL1[2] = 1; HL1[3] = 0; HL1[4] = 0; HL1[5] = 0; + h_s1=0; h_s =0; + } + if(count_menu == 3){ + HL1[0] = 0; HL1[1] = 0; HL1[2] = 0; HL1[3] = 1; HL1[4] = 0; HL1[5] = 0; + h_s1=0; h_s =0; + } + if(count_menu == 4){ + HL1[0] = 0; HL1[1] = 0; HL1[2] = 0; HL1[3] = 0; HL1[4] = 1; HL1[5] = 0; + h_s1=0; h_s =0; + + } + if(count_menu == 5){ + HL1[0] = 0; HL1[1] = 0; HL1[2] = 0; HL1[3] = 0; HL1[4] = 0; HL1[5] = 1; + h_s1=0; h_s =0; + } + if(count_menu ==6){ + HL1[0] = 0; HL1[1] = 0; HL1[2] = 0; HL1[3] = 0; HL1[4] = 0; HL1[5] = 0; + h_s1=1; h_s =0; + } + if(count_menu ==7){ + HL1[0] = 0; HL1[1] = 0; HL1[2] = 0; HL1[3] = 0; HL1[4] = 0; HL1[5] = 0; + h_s1=0; h_s =1; + } + if(count_menu ==-1){ + count_menu = 0; + } + if(count_menu ==8){ + count_menu = 7; + } + + if(HL1[0]==1){ + if(analong_data>0.98){ + num1 -= 1; + }else if(analong_data<0.55 && analong_data>0.3){ + num1 += 1; + } + if(num1 == -1){ + num1 =9; + } + if(num1 == 10){ + num1 =0; + } + sprintf(pass1, "%d", num1); + } + + if(HL1[1]==1){ + if(analong_data>0.98){ + num2 -= 1; + }else if(analong_data<0.55 && analong_data>0.3){ + num2 += 1; + } + if(num2 == -1){ + num2 =9; + } + if(num2 == 10){ + num2 =0; + } + sprintf(pass2, "%d", num2); + } + + if(HL1[2]==1){ + if(analong_data>0.98){ + num3 -= 1; + }else if(analong_data<0.55 && analong_data>0.3){ + num3 += 1; + } + if(num3 == -1){ + num3 =9; + } + if(num3 == 10){ + num3 =0; + } + sprintf(pass3, "%d", num3); + } + + if(HL1[3]==1){ + if(analong_data>0.98){ + num4 -= 1; + }else if(analong_data<0.55 && analong_data>0.3){ + num4 += 1; + } + if(num4 == -1){ + num4 =9; + } + if(num4 == 10){ + num4 =0; + } + sprintf(pass4, "%d", num4); + } + + if(HL1[4]==1){ + if(analong_data>0.98){ + num5 -= 1; + }else if(analong_data<0.55 && analong_data>0.3){ + num5 += 1; + } + if(num5 == -1){ + num5 =9; + } + if(num5 == 10){ + num5 =0; + } + sprintf(pass5, "%d", num5); + } + + if(HL1[5]==1){ + if(analong_data>0.98){ + num6 -= 1; + }else if(analong_data<0.55 && analong_data>0.3){ + num6 += 1; + } + if(num6 == -1){ + num6 =9; + } + if(num6 == 10){ + num6 =0; + } + sprintf(pass6, "%d", num6); + } +////////////////////////////////check with another nucleo///////////////////////////////////////////// + show.LCD_write_string( 0, 0,"Open-Password", MENU_NORMAL); + show.LCD_write_string( 0, 2,pass1,HL1[0] ); + show.LCD_write_string( 6, 2,"-",MENU_NORMAL); + show.LCD_write_string( 12, 2,pass2,HL1[1] ); + show.LCD_write_string( 18, 2,"-",MENU_NORMAL ); + show.LCD_write_string( 24, 2,pass3,HL1[2] ); + show.LCD_write_string( 30, 2,"-",MENU_NORMAL); + show.LCD_write_string( 36, 2,pass4,HL1[3] ); + show.LCD_write_string( 42, 2,"-",MENU_NORMAL ); + show.LCD_write_string( 48, 2,pass5,HL1[4] ); + show.LCD_write_string( 54, 2,"-",MENU_NORMAL ); + show.LCD_write_string( 60, 2,pass6,HL1[5] ); + show.LCD_write_string( 0, 4,"<OK>", h_s1); + show.LCD_write_string( 0, 5,"<Back", h_s); + + if(h_s == 1 ){ + if(analong_data>0.15 && analong_data<0.3){ + show.LCD_clear(); + count_menu =0; + state_menu =0; + } + } +} + +void menu_register(){ + if(analong_data>0.98){ + count_menu -= 1; + }else if(analong_data<0.55 && analong_data>0.3){ + count_menu += 1; + } + + if(count_menu == 1){ + h_s=1; + } + else if(count_menu == 0){ + h_s=0; + }else{ + count_menu = 0; + } + show.LCD_write_string( 0, 0,"Register-RFID", MENU_NORMAL); + show.LCD_write_string( 0, 5,"<Back", h_s); + + if(h_s == 1 ){ + if(analong_data>0.15 && analong_data<0.3){ + show.LCD_clear(); + state_menu =0; + } + } + +} \ No newline at end of file