eiei

Dependencies:   mbed

Fork of RFID-RC522 by Thomas Kirchner

Revision:
3:096e1c284971
Parent:
2:a0c7513fb634
--- a/main.cpp	Fri Jun 06 03:04:48 2014 +0000
+++ b/main.cpp	Mon Dec 05 11:24:06 2016 +0000
@@ -1,40 +1,25 @@
-//Test of cheap 13.56 Mhz RFID-RC522 module from eBay
-//This code is based on Martin Olejar's MFRC522 library. Minimal changes
-//Adapted for Nucleo STM32 F401RE. Should work on other Nucleos too
-
-//Connect as follows:
-//RFID pins        ->  Nucleo header CN5 (Arduino-compatible header)
-//----------------------------------------
-//RFID IRQ=pin5    ->   Not used. Leave open
-//RFID MISO=pin4   ->   Nucleo SPI_MISO=PA_6=D12
-//RFID MOSI=pin3   ->   Nucleo SPI_MOSI=PA_7=D11
-//RFID SCK=pin2    ->   Nucleo SPI_SCK =PA_5=D13
-//RFID SDA=pin1    ->   Nucleo SPI_CS  =PB_6=D10
-//RFID RST=pin7    ->   Nucleo         =PA_9=D8
-//3.3V and Gnd to the respective pins                              
-                              
 #include "mbed.h"
 #include "MFRC522.h"
-
-// Nucleo Pin for MFRC522 reset (pick another D pin if you need D8)
 #define MF_RESET    D8
-
+Serial pc(SERIAL_TX, SERIAL_RX);
+Serial tu(PA_11, PA_12);
+MFRC522    RfChip   (PC_12, PC_11, PC_10, PC_8, MF_RESET);
 DigitalOut LedGreen(LED1);
 
-//Serial connection to PC for output
-Serial pc(SERIAL_TX, SERIAL_RX);
+int main(void) {
 
-MFRC522    RfChip   (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
-
-int main(void) {
   pc.printf("starting...\n");
 
-  // Init. RC522 Chip
   RfChip.PCD_Init();
 
+  uint8_t ID[8];
+  uint8_t ID1[8]={0x3B,0xED,0x13,0x80};//Wan
+  uint8_t ID2[8]={0x4B,0xA9,0x14,0x80};//Gus
+  uint8_t ID3[8]={0x5B,0x18,0x12,0x80};//Wisa
+  uint8_t ID4[8]={0x3B,0x1A,0x12,0x80};//Tew
+
   while (true) {
     LedGreen = 1;
-
     // Look for new cards
     if ( ! RfChip.PICC_IsNewCardPresent())
     {
@@ -50,18 +35,33 @@
     }
 
     LedGreen = 0;
+    // Print Card UID
 
-    // Print Card UID
     pc.printf("Card UID: ");
     for (uint8_t i = 0; i < RfChip.uid.size; i++)
     {
-      pc.printf(" %X02", RfChip.uid.uidByte[i]);
+      pc.printf(" %X", RfChip.uid.uidByte[i]);
+      ID[i]=RfChip.uid.uidByte[i];
     }
     pc.printf("\n\r");
-
-    // Print Card type
-    uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak);
-    pc.printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType));
-    wait_ms(1000);
+    if (ID[0]==ID1[0]&&ID[1]==ID1[1]&&ID[2]==ID1[2]&&ID[3]==ID1[3]){
+        pc.printf("Wan's Card\n");
+        tu.printf("G");
+        }
+    else if(ID[0]==ID2[0]&&ID[1]==ID2[1]&&ID[2]==ID2[2]&&ID[3]==ID2[3]){
+        pc.printf("Gus's Card\n");
+        tu.printf("J");
+        }
+    else if(ID[0]==ID3[0]&&ID[1]==ID3[1]&&ID[2]==ID3[2]&&ID[3]==ID3[3]){
+        pc.printf("Wisa's Card\n");
+        tu.printf("H");
+        }
+    else if(ID[0]==ID4[0]&&ID[1]==ID4[1]&&ID[2]==ID4[2]&&ID[3]==ID4[3]){
+        pc.printf("Tew's Card\n");
+        tu.printf("K");
+        }
+    else{
+        return (0);
+        }
   }
-}
\ No newline at end of file
+}