แก้ให้แล้ว

Dependencies:   NOKIA_5110 mbed

Fork of Lost-Found_BOX by FRA221:A

Revision:
3:c927196a726f
Parent:
2:5764ad3214cd
Child:
4:75346bd905c0
--- a/main.cpp	Sun Dec 06 10:23:43 2015 +0000
+++ b/main.cpp	Sun Dec 06 22:51:40 2015 +0000
@@ -22,6 +22,7 @@
 //Serial connection to PC for output
 Serial pc(SERIAL_TX, SERIAL_RX);
 PwmOut speaker(D3);
+DigitalOut lock(D2);
 MFRC522    RfChip   (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
 
 void GetID(uint8_t ID[])
@@ -31,9 +32,37 @@
       ID[i] = RfChip.uid.uidByte[i];
     };  
 }
+void speak()
+{
+    speaker.period_ms(1);
+    speaker.write(0.1f);
+    wait(0.2);
+    speaker.write(0);
+}
+void speakRight()
+{
+    speaker.period_ms(1);
+    speaker.write(0.1f);
+    wait(1);
+    speaker.write(0);
+}
+void speakWrong()
+{
+    speaker.period_ms(1);
+    speaker.write(0.1f);
+    wait(0.2);
+    speaker.write(0);
+    wait(0.1);
+    speaker.write(0.1f);
+    wait(0.2);
+    speaker.write(0);
+}
+void checkRight()
+{
+}
 int main(void) {
     uint8_t RFID[10];
-    int check=0;   
+    int check=0;
     LcdPins myPins;      
     myPins.sce  = PB_4;  //D5 ActiveLow SlaveSelect
     myPins.rst  = PB_10; //D6
@@ -81,6 +110,10 @@
             myLcd.DrawString("Right!!  ");   
             myLcd.stop();
             check = 0;
+            lock = 1;
+            speakRight();
+            wait(2.5);
+            lock = 0;
             continue;
         }
         else 
@@ -89,6 +122,7 @@
             myLcd.InitLcd();              
             myLcd.DrawString("Wrong!!  ");   
             myLcd.stop();
+            speakWrong();
             continue;
         }
     }
@@ -105,8 +139,9 @@
     {
       pc.printf(" %X", RfChip.uid.uidByte[i]);
     }
-    
+    speak();
     GetID(RFID);
+    lock = 0;
     pc.printf("\n\r");   
     wait_ms(1000);
     check = 1;