get an input from RFID to control the LCD

Dependencies:   mbed

Fork of LCD4884 by Dan Ghiciulescu

Revision:
3:dbe254844345
Parent:
2:fb07a736e132
Child:
4:5977fe753a55
--- a/main.cpp	Mon Dec 11 07:39:34 2017 +0000
+++ b/main.cpp	Mon Dec 11 12:49:26 2017 +0000
@@ -19,13 +19,12 @@
 Serial pc(SERIAL_TX, SERIAL_RX);
 MFRC522    RfChip   (PC_12, PC_11, PC_10, SPI_CS, MF_RESET);
 
-
 int main(void)
 {
     p.LCD_init();
     p.LCD_write_string(28,2,"Hello",MENU_NORMAL);
     uint8_t state = 0;
-    double select, press, ss_analysis;
+    double select, press;
     int line, rfid_ID;
 
     int row1 = 2;
@@ -35,9 +34,14 @@
     int row5 = 282;
     int n = 0;
 
-    float sensor[6] = {40,20,10,16,27,33};
+    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};                                   
 
-    unsigned char img[] = {
+    unsigned char img[] = {                                                     //graph
         128,255,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
@@ -73,12 +77,10 @@
 
         select = analog_button_select.read();
         press = analog_button_press.read();
-        ss_analysis = analog_button_alarm.read();
-
-        printf("x = %f\n",select);
+        printf("home page");
 
         n = 0;
-        while (n != 6) {
+        while (n != 60) {
             //Start Row5
             if (sensor[n] == 1) {
                 img[row5+n] = 128;
@@ -104,7 +106,7 @@
             //End Row5
 
             //Start Row4
-            if (sensor[n] == 2) {
+            if (sensor[n] == 11) {
                 img[row4+n] = 128;
             } else if (sensor[n] == 12) {
                 img[row4+n] = 64;
@@ -128,7 +130,7 @@
             //End Row4
 
             //Start Row3
-            if (sensor[n] == 3) {
+            if (sensor[n] == 21) {
                 img[row3+n] = 128;
             } else if (sensor[n] == 22) {
                 img[row3+n] = 64;
@@ -152,7 +154,7 @@
             //End Row3
 
             //Start Row2
-            if (sensor[n] == 4) {
+            if (sensor[n] == 31) {
                 img[row2+n] = 128;
             } else if (sensor[n] == 32) {
                 img[row2+n] = 64;
@@ -176,7 +178,7 @@
             //End Row2
 
             //Start Row1
-            if (sensor[n] == 5) {
+            if (sensor[n] == 41) {
                 img[row1+n] = 128;
             } else if (sensor[n] == 42) {
                 img[row1+n] = 64;
@@ -205,21 +207,34 @@
             p.backlight(0);
             p.LCD_write_string(28,2,"Hello",MENU_NORMAL);
             printf("I am in home page\n");
+
             rfid_ID = ReadRFID();
 
-            if (ss_analysis == 0) {                                             // Alarm Page
-                printf("Alarm detected");
+            if (rfid_ID == 0) {
+                printf("Admin detected\n");
+                p.LCD_clear();
+                state = 1;
+            }
+
+            if (rfid_ID == 1) {
+                printf("Alarm detected\n");
                 p.LCD_clear();
                 state = 2;
-            } else {
-                if (rfid_ID == 0) {
-                    printf("Admin detected");
-                    p.LCD_clear();
-                    state = 1;
-                } else break;
             }
+        }
 
-        }
+        /*           if (ss_analysis == 0) {                                             // Alarm Page
+                       printf("Alarm detected");
+                       p.LCD_clear();
+                       state = 2;
+                   } else {
+                       if (rfid_ID == 0) {
+                           printf("Admin detected");
+                           p.LCD_clear();
+                           state = 1;
+                       } else break;
+                   }
+        */
 
         else if (state == 1) {                                                  //Admin Page
             p.backlight(1);
@@ -371,6 +386,13 @@
                 p.LCD_write_string(25,1,"PEASE",MENU_NORMAL);
                 p.LCD_write_string(10,3,"TAP ID CARD",MENU_NORMAL);
                 wait_ms(250);
+                /*
+                if (rfid_ID == 1) {
+                    printf("User detected");
+                    p.LCD_clear();
+                    state = 0;
+                }
+                */
             }
         }
 
@@ -379,14 +401,15 @@
 
 int ReadRFID()
 {
-    int data[10];
-    int card;
+    int data[10], card ;
+    float ss;
     pc.printf("starting...\n");
+    ss = analog_button_alarm.read();
 
     // Init. RC522 Chip
     RfChip.PCD_Init();
 
-    while(true) {
+    while (true) {
         LedGreen = 1;
 
         // Look for new cards
@@ -409,6 +432,8 @@
             wait_ms(500);
             continue;
         }
+
+
         LedGreen = 0;
 
         // Print Card UID
@@ -427,4 +452,4 @@
 
         pc.printf("\n\r");
     }
-}
\ No newline at end of file
+}