I was able to work this one out by looking at the return values from MFRC522_Request(PICC_REQIDL, str)
.
I created RFID_status as an int and also created RFID_read as an int and set to 0.
I then used RFID_status to test to see if there was an active card connection. If yes and RFID_read was still 0 then read the card and set RFID_read to 1. That way in the next loop the card will not be read.
Once the the card is taken away RFID_status will read as 0 (No connection) and RFID_read will be set back to 0.
int RFID_status;
int RFID_read = 0;
void loop()
{
uchar status;
uchar str[MAX_LEN];
// Search card, return card types
RFID_status = MFRC522_Request(PICC_REQIDL, str);
if (RFID_status != 1)
{
RFID_read 0;
}
// Show card type
ShowCardType(str);
//Prevent conflict, return the 4 bytes Serial number of the card
status = MFRC522_Anticoll(str);
// str[0..3]: serial number of the card
// str[4]: XOR checksum of the SN.
if (RFID_status == 1 && RFID_read == 0)
{
Serial.print("The card's number is: ");
memcpy(serNum, str, 5);
ShowCardID(serNum);
RFID_read = 1;
// Check people associated with card ID
uchar* id = serNum;
if (id[0] == 0x4B && id[1] == 0xE6 && id[2] == 0xD1 && id[3] == 0x3B) {
Serial.println("Hello Mary!");
RFID_read = 1;
}
else if (id[0] == 0x3B && id[1] == 0xE6 && id[2] == 0xD1 && id[3] == 0x3B) {
Serial.println("Hello Greg!");
RFID_read = 1;
}
else{
Serial.println("Hello unkown guy!");
RFID_read = 1;
}
}
MFRC522_Halt(); //command the card into sleep mode
delay(2000);
}
NB: There is a lot of code in this sketch that I have taken out. I have only included the void loop and the two global variables that I created. The original sketch can be found here: MiFare RFID-RC522 Sketch