[英]Arduino C++ String variables with RFID
我正在嘗試掃描 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 loop() 中而不是在它自己的函數中,名為 rfidMenu() ,它是從rfidOpen() 無效,如代碼所示。
這是我的代碼:
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();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.