mix

Dependencies:   mbed Servo MFRC522 UniGraphic

Revision:
11:3f04152789d8
Parent:
10:409551ce66c9
Child:
12:4829da055199
--- a/main.cpp	Mon Dec 17 08:57:23 2018 +0000
+++ b/main.cpp	Tue Dec 18 19:10:53 2018 +0000
@@ -13,6 +13,7 @@
 #define MF_RESET PC_6
 #include "Servo.h"
 ///////////////////////////////////////////////////////////////////////////////
+Serial esp(PA_15,PB_7);
 Serial pc(SERIAL_TX, SERIAL_RX);
 MFRC522    RfChip   (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
 PinName buspins[] = { PA_9, PC_7, PA_10, PB_3, PB_5, PB_4, PB_10, PA_8 };
@@ -33,11 +34,15 @@
 int Pagejawjiw = 0;
 int state = 0;
 int main(){
+    char Type;
+    char StD;
+    char Num;
+    char Jaw1[3]={};
+    char Jaw2[3]={};
     char *StudentID;
     uint8_t UIDCard[4]={};
     pc.printf("starting...\n");
     RfChip.PCD_Init();
-
     myLCD.set_orientation(orient);
     int time;
     t.start();
@@ -45,11 +50,6 @@
     myLCD.foreground(foregroundcolor);    
     myLCD.cls();
     
-    for(float p=0; p<1.0; p += 0.1) {
-         myservo1 = p;
-         myservo2 = 1.0;
-     }
-
     while(1){  
         if(Pagejawjiw == 0){
             myLCD.background(backgroundcolor);    
@@ -58,7 +58,6 @@
             myLCD.fillrect(0,320,500,280,Orange);
             time=t.read_us();
             if(! RfChip.PICC_IsNewCardPresent()){
-                  pc.printf("GOOOOOOOOO\n");
                   for(int i=200; i<=200;i++){
                     myLCD.locate(i,295);
                     myLCD.printf("Please scan your Student ID card to start.");}
@@ -66,11 +65,15 @@
                     myLCD.locate(i,295);
                     myLCD.printf("Please scan your Student ID card to start.");}
                   continue;}
-            if ( ! RfChip.PICC_ReadCardSerial()){pc.printf("!!!!!!!!!!!!!!!");continue;}
+            if ( ! RfChip.PICC_ReadCardSerial()){continue;}
             pc.printf("Studen's ID: ");
             for (uint8_t i = 0; i < RfChip.uid.size; i++){UIDCard[i] = RfChip.uid.uidByte[i];}
-            if (UIDCard[0]==187 and UIDCard[1]==164 and UIDCard[2]==90 and UIDCard[3]==127){StudentID = "60340500033"; pc.printf("%s\n",StudentID);Pagejawjiw = 1;myLCD.cls();}
-            else if (UIDCard[0]==60 and UIDCard[1]==135 and UIDCard[2]==56 and UIDCard[3]==59){StudentID = "60340500066"; pc.printf("%s\n",StudentID);Pagejawjiw = 0;}
+            if (UIDCard[0]==187 and UIDCard[1]==164 and UIDCard[2]==90 and UIDCard[3]==127){StudentID = "60340500033";StD='X';pc.printf("%s\n",StudentID);Pagejawjiw = 1;myLCD.cls();}
+            else if (UIDCard[0]==60 and UIDCard[1]==135 and UIDCard[2]==56 and UIDCard[3]==59){StudentID = "60340500066";StD='Y';pc.printf("%s\n",StudentID);Pagejawjiw = 0;}
+            else if (UIDCard[0]==152 and UIDCard[1]==63 and UIDCard[2]==31 and UIDCard[3]==137){pc.printf("%s\n",Jaw1[0]);
+                esp.putc('A');esp.putc(Jaw1[0]);esp.putc(Jaw1[1]);esp.putc(Jaw1[2]);Jaw1[0]=' ';Jaw1[1]=' ';Jaw1[2]=' ';} //ฝาเปิด
+            else if (UIDCard[0]==21 and UIDCard[1]==86 and UIDCard[2]==31 and UIDCard[3]==137){pc.printf("%s\n",Jaw2[0]);
+                esp.putc('A');esp.putc(Jaw2[0]);esp.putc(Jaw2[1]);esp.putc(Jaw2[2]);Jaw2[0]=' ';Jaw2[1]=' ';Jaw2[2]=' ';} //ฝาเปิด
             else {StudentID="0"; pc.printf("%s\n",StudentID);}
             }
         else if (Pagejawjiw == 1) {
@@ -335,6 +338,10 @@
                     }
                 else if(Sw[4] == 0){
                     Pagejawjiw++;
+                    if(i==1){Type = '1';}
+                    else if(i==2){Type = '2';}
+                    else if(i==3){Type = '3';}
+                    else if(i==4){Type = '4';}
                     wait(0.3);
                     }
                 }
@@ -409,6 +416,8 @@
                     }
                 else if(Sw[4] == 0){
                     Pagejawjiw++;
+                    if(j==1){Jaw1[0]=Type;Jaw1[1]=StD;Jaw1[2]=Num;}
+                    else if(j==2){Jaw2[0]=Type;Jaw2[1]=StD;Jaw2[2]=Num;}
                     wait(0.3);
                     myLCD.cls();
                     k=0;
@@ -458,6 +467,12 @@
                 }
                 }
             else if(Pagejawjiw == 4){
+                for(float p=1.0; p>=0.0; p -= 0.1) {
+                     myservo1 = 0.0;
+                     myservo2 = p;
+                     wait(0.2);
+                     break;
+                 }
                 myLCD.cls();
                 myLCD.background(backgroundcolor);
                 myLCD.foreground(foregroundcolor);