【发布时间】:2014-05-13 13:37:17
【问题描述】:
我刚刚拿到了用于 arduino 的 RC522 RFID 卡,并且正在使用提供的草图。 MiFare RFID-RC522
我坚持的是理解如何在读取卡片时暂停草图,以便只读取一次。在卡连接到 RDIF 读卡器的那一刻,草图将保持循环并每次读取卡。
可以设置一个延迟,但如果连接时间超过延迟,最终会再次读取卡。
我想说的是,当有卡连接时,只读取一次卡 ID,然后在卡连接断开时继续草图。
这是主要的草图部分:
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);
}
谢谢各位。
【问题讨论】: