首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用RFID的Arduino C++字符串变量

使用RFID的Arduino C++字符串变量
EN

Stack Overflow用户
提问于 2020-03-27 23:26:46
回答 1查看 347关注 0票数 0

我正在尝试扫描一个RFID标签,将其添加到一个名为RFID1的变量字符串中。然而,当它在另一个void函数中的do while循环中扫描RFID卡时,它总是说访问被拒绝,就好像它仍然在主循环中一样。

我不知道为什么会发生这种事..

代码语言:javascript
复制
 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添加到变量中。^^

代码语言:javascript
复制
 // ---- 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调用的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-27 23:42:26

这是我的代码:

代码语言:javascript
复制
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();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60889068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档