get an input from RFID to control the LCD

Dependencies:   mbed

Fork of LCD4884 by Dan Ghiciulescu

Files at this revision

API Documentation at this revision

Comitter:
Pinmanee
Date:
Mon Dec 11 15:10:01 2017 +0000
Parent:
3:dbe254844345
Commit message:
LCD that can show graph

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Dec 11 12:49:26 2017 +0000
+++ b/main.cpp	Mon Dec 11 15:10:01 2017 +0000
@@ -5,7 +5,7 @@
 #define MF_RESET    D8
 #define SPI_CS      D10
 
-int ReadRFID();
+int ReadRFID_forLCD();
 
 //LCD
 AnalogIn analog_button_select(A0);
@@ -19,7 +19,7 @@
 Serial pc(SERIAL_TX, SERIAL_RX);
 MFRC522    RfChip   (PC_12, PC_11, PC_10, SPI_CS, MF_RESET);
 
-int main(void)
+int main()
 {
     p.LCD_init();
     p.LCD_write_string(28,2,"Hello",MENU_NORMAL);
@@ -32,14 +32,14 @@
     int row3 = 142;
     int row4 = 212;
     int row5 = 282;
-    int n = 0;
 
-    float sensor[60] = {8,0,0,0,0,0,0,0,0,0,                                     //sensor input for graph
-                        16,0,0,0,0,0,0,0,0,0,
-                        24,0,0,0,0,0,0,0,0,0,
-                        32,0,0,0,0,0,0,0,0,0,
-                        40,0,0,0,0,0,0,0,0,0,
-                        48,0,0,0,0,0,0,0,0,0};                                   
+    float sensor[60] = {7,0,0,0,0,0,0,0,0,14,                                  //sensor input for graph
+                        0,0,0,0,0,0,0,0,0,21,
+                        0,0,0,0,0,0,0,0,0,28,
+                        0,0,0,0,0,0,0,0,0,35,
+                        0,0,0,0,0,0,0,0,0,42,
+                        0,0,0,0,0,0,0,0,0,49
+                       };
 
     unsigned char img[] = {                                                     //graph
         128,255,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
@@ -77,9 +77,10 @@
 
         select = analog_button_select.read();
         press = analog_button_press.read();
-        printf("home page");
 
-        n = 0;
+        printf("Program started\n");
+
+        int n = 0;
         while (n != 60) {
             //Start Row5
             if (sensor[n] == 1) {
@@ -208,7 +209,8 @@
             p.LCD_write_string(28,2,"Hello",MENU_NORMAL);
             printf("I am in home page\n");
 
-            rfid_ID = ReadRFID();
+            rfid_ID = ReadRFID_forLCD();
+            //printf("ID = %d\n",rfid_ID);
 
             if (rfid_ID == 0) {
                 printf("Admin detected\n");
@@ -216,14 +218,14 @@
                 state = 1;
             }
 
-            if (rfid_ID == 1) {
+            else if (rfid_ID == 1) {
                 printf("Alarm detected\n");
                 p.LCD_clear();
                 state = 2;
             }
         }
 
-        /*           if (ss_analysis == 0) {                                             // Alarm Page
+        /*           if (ss_analysis == 0) {                    // Alarm Page
                        printf("Alarm detected");
                        p.LCD_clear();
                        state = 2;
@@ -236,6 +238,7 @@
                    }
         */
 
+
         else if (state == 1) {                                                  //Admin Page
             p.backlight(1);
             p.LCD_write_string(25,0,"Admin",MENU_HIGHLIGHT);
@@ -249,7 +252,7 @@
                 select = analog_button_select.read();
                 press = analog_button_press.read();
 
-                if (select != 0 && press != 0) {                          // no press
+                if (select != 0 && press != 0) {                                // no press
                     if (line == 1) {
                         p.LCD_write_string(25,0,"Admin",MENU_NORMAL);
                         p.LCD_write_string(0,1,"- Motion Graph",MENU_HIGHLIGHT);    //line = 0
@@ -283,7 +286,7 @@
                     }
                 }
 
-                else if (select == 0) {      // channel selecting button (down)
+                else if (select == 0) {                                         // channel selecting button (down)
                     if (line < 4) {
                         //printf("line = %d\n",line);
                         line = line + 1;
@@ -291,7 +294,7 @@
                     } else line = 0;
                 }
 
-                else if (press == 0) {      // press button
+                else if (press == 0) {                                          // press button
                     //printf("i am in\n");
                     //printf("line = %d\n",line);
 
@@ -386,8 +389,9 @@
                 p.LCD_write_string(25,1,"PEASE",MENU_NORMAL);
                 p.LCD_write_string(10,3,"TAP ID CARD",MENU_NORMAL);
                 wait_ms(250);
+                rfid_ID = ReadRFID_forLCD();
                 /*
-                if (rfid_ID == 1) {
+                if (rfid_ID == 1) {                                             // If user tap the card, get out of the loop
                     printf("User detected");
                     p.LCD_clear();
                     state = 0;
@@ -399,18 +403,17 @@
     }
 }
 
-int ReadRFID()
+
+int ReadRFID_forLCD()
 {
-    int data[10], card ;
+    int data[10], card;
     float ss;
     pc.printf("starting...\n");
-    ss = analog_button_alarm.read();
 
     // Init. RC522 Chip
     RfChip.PCD_Init();
 
-    while (true) {
-        LedGreen = 1;
+    while (1) {
 
         // Look for new cards
         if(data[0] == 199 && data[1] == 230 &&data[2] == 46 &&data[3] == 0 ) {
@@ -433,9 +436,6 @@
             continue;
         }
 
-
-        LedGreen = 0;
-
         // Print Card UID
         pc.printf("Card UID: ");
         for (uint8_t i = 0; i < RfChip.uid.size; i++) {
@@ -443,13 +443,6 @@
             pc.printf("%d ", data[i]);
 
         }
-
-        //pc.printf("\n\r");
-        //pc.printf("\n\r");
-        //char data[0];
-        //pc.printf("  %X02", data[0]);
-        //pc.printf("  %s\n", data[0]);
-
         pc.printf("\n\r");
     }
 }