我正在尝试扫描一个RFID标签,将其添加到一个名为RFID1的变量字符串中。然而,当它在另一个void函数中的do while循环中扫描RFID卡时,它总是说访问被拒绝,就好像它仍然在主循环中一样。
我不知道为什么会发生这种事..
do{ // DO WHILE STATEMENT FOR ADDING RFID
if
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
RFID1 == content.substring(1); // RFID USER 1 = RFID TAG
delay(3000); // WAIT 3 SECONDS
user1AddLoop + 1; // BREAK OUT OF LOOP
} // END OF DO WHILE STATEMENT FOR ADDING RFID
while(user1AddLoop == 0 );^^函数,用于尝试将RFID添加到变量中。^^
// ---- RFID CODE ---- //
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : SCAN YOUR RFID TAG");
content.toUpperCase();
if (content.substring(1) == RFID1 || content.substring(1) == RFID2 || content.substring(1) == RFID3) //change here the UID of the card/cards that you want to give access
{
rfidOpen();
}
else {
rfidDeny();
}^^搜索RFID以打开主回路中的门的代码^^
我知道他们使用相同的代码来搜索RFID,然而,我不能理解为什么它总是拒绝我的访问,就好像它是在void循环()中,而不是在它自己的名为rfidMenu()的函数中,该函数是从代码中看到的rfidOpen() void调用的。
发布于 2020-03-27 23:42:26
这是我的代码:
void readCard()
{
cardContent = "";
if ( ! mfrc522.PICC_IsNewCardPresent() )
return;
if ( ! mfrc522.PICC_ReadCardSerial() )
return;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
cardContent.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
cardContent.concat(String(mfrc522.uid.uidByte[i], HEX));
}
cardContent.toUpperCase();
}https://stackoverflow.com/questions/60889068
复制相似问题