I just got hold of the RC522 RFID card for arduino and am working with the supplied sketch. MiFare RFID-RC522
What I am stuck on is understanding how pause the sketch while the card is being read so it is only read once. At the moment while the card is connected to the RDIF reader the sketch will keep looping and read the card each time.
There is a delay that can be set but will eventually read the card again if it is connected longer than the delay.
What I would like is to be able to say while there is a card connection, read the card ID only once then continue the sketch when the card connection is broken.
This is the main sketch segment:
void loop()
{
uchar status;
uchar str[MAX_LEN];
// Search card, return card types
status = MFRC522_Request(PICC_REQIDL, str);
if (status != MI_OK)
{
return;
}
// 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 (status == MI_OK)
{
Serial.print("The card's number is: ");
memcpy(serNum, str, 5);
ShowCardID(serNum);
// 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!");
}
else if (id[0] == 0x3B && id[1] == 0xE6 && id[2] == 0xD1 && id[3] == 0x3B) {
Serial.println("Hello Greg!");
}
else{
Serial.println("Hello unkown guy!");
}
}
MFRC522_Halt(); //command the card into sleep mode
delay(2000);
}
Thanks Guys.