简体   繁体   English

带有 RFID 的 Arduino C++ 字符串变量

[英]Arduino C++ String variables with RFID

I'm trying to scan a RFID tag to add it to a variable string named RFID1.我正在尝试扫描 RFID 标签以将其添加到名为 RFID1 的变量字符串中。 However, it keeps saying access denied as if it were still in the main loop when scanning the RFID card when it is in a do while loop in another void function.然而,当它在另一个 void 函数中的 do while 循环中时,它在扫描 RFID 卡时一直说访问被拒绝,就好像它仍然在主循环中一样。

I'm not sure why this is happening..我不确定为什么会这样..

 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 );

^^ Function for trying to add RFID to the variable. ^^ 尝试将 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();
  }

^^ Code for searching RFID to open door in main loop ^^ ^^ 在主循环中搜索RFID开门的代码^^

I am aware they use the same code to search for RFID, however, I cannot understand why it keeps giving me access denied as if it was in the void loop() instead of in it's own function, named rfidMenu() which is called from the rfidOpen() void as seen in the code.我知道他们使用相同的代码来搜索 RFID,但是,我不明白为什么它总是让我拒绝访问,好像它在 void loop() 中而不是在它自己的函数中,名为 rfidMenu() ,它是从rfidOpen() 无效,如代码所示。

This is my code:这是我的代码:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM