menu LCD4884 locker

Dependencies:   mbed mbed

Fork of LCD4884 by Dan Ghiciulescu

Files at this revision

API Documentation at this revision

Comitter:
Aussawin
Date:
Sun Dec 10 06:11:35 2017 +0000
Parent:
0:28f3c9274ea7
Commit message:
test

Changed in this revision

LCD4884.cpp Show annotated file Show diff for this revision Revisions of this file
LCD4884.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mbed.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 28f3c9274ea7 -r 452282f5895f LCD4884.cpp
--- a/LCD4884.cpp	Sat Mar 09 21:07:35 2013 +0000
+++ b/LCD4884.cpp	Sun Dec 10 06:11:35 2017 +0000
@@ -14,18 +14,18 @@
 #include "font_6x8.h"
 #include "font_big.h"
 
-DigitalOut SpiClk(SPI_SCK);    //2- Serial Clock(Master Output)
-DigitalOut SpiMosi(SPI_MOSI);  //3- Master Output,Slave Input
-DigitalOut LcdDC(LCD_DC);      //4- Data/Command(command active low)
-DigitalOut SpiCS(SPI_CS);      //5- Chip Select,Slave Transmit Enable(active low,Master Output)
-DigitalOut LcdRst(LCD_RST);    //6- One Reset button
-PwmOut     LcdBl(LCD_BL);      //7- LCD backlight
+DigitalOut SpiClk(D2);    //2- Serial Clock(Master Output)
+DigitalOut SpiMosi(D3);  //3- Master Output,Slave Input
+DigitalOut LcdDC(D4);      //4- Data/Command(command active low)
+DigitalOut SpiCS(D5);      //5- Chip Select,Slave Transmit Enable(active low,Master Output)
+DigitalOut LcdRst(D6);    //6- One Reset button
+PwmOut     LcdBl(D7);      //7- LCD backlight
 
 LCD4884::LCD4884()
 {};
 
 /******************************************************************/
-void LCD4884::backlight(float dat)
+void LCD4884::backlight(int dat)
 {
     LcdBl = dat;
 }
diff -r 28f3c9274ea7 -r 452282f5895f LCD4884.h
--- a/LCD4884.h	Sat Mar 09 21:07:35 2013 +0000
+++ b/LCD4884.h	Sun Dec 10 06:11:35 2017 +0000
@@ -16,12 +16,12 @@
 #include "mbed.h"
 
 // SPI Interface --- (on arduino Arduino Digital Pin 2,3,4,5,6)
-#define SPI_SCK  PTD4   //Serial Clock(Master Output)
-#define SPI_MOSI PTA12  //Master Output,Slave Input
-#define LCD_DC   PTA4   //Data/Command(command active low)
-#define SPI_CS   PTA5   //Chip Select,Slave Transmit Enable(active low,Master Output)
-#define LCD_RST  PTC8   //One Reset button
-#define LCD_BL   PTC9   //PWM Backlit control (Arduino DIO Pin 7)
+#define SPI_SCK  D2   //Serial Clock(Master Output)
+#define SPI_MOSI D3  //Master Output,Slave Input
+#define LCD_DC   D4   //Data/Command(command active low)
+#define SPI_CS   D5   //Chip Select,Slave Transmit Enable(active low,Master Output)
+#define LCD_RST  D6   //One Reset button
+#define LCD_BL   D7   //PWM Backlit control (Arduino DIO Pin 7)
 
 
 //display mode -- normal / highlight
@@ -41,7 +41,7 @@
     public:
     LCD4884();
     void LCD_init(void);
-    void backlight(float dat);
+    void backlight(int dat);
     void LCD_write_byte(unsigned char dat, unsigned char dat_type);
     void LCD_draw_bmp_pixel(unsigned char X,unsigned char Y,unsigned char *map,unsigned char Pix_x,unsigned char Pix_y);
     void LCD_write_string(unsigned char X,unsigned char Y,char *s, char mode);
diff -r 28f3c9274ea7 -r 452282f5895f main.cpp
--- /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
diff -r 28f3c9274ea7 -r 452282f5895f mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Dec 10 06:11:35 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e7ca05fa8600
\ No newline at end of file
diff -r 28f3c9274ea7 -r 452282f5895f mbed.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.lib	Sun Dec 10 06:11:35 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/gokmenascioglu/code/mbed/#a8fa94490a0a