1

我想用 Arduino Leonardo 将卡的 UID 打印为 HID。

这是我的代码

void loop() {
if (  mfrc522.PICC_IsNewCardPresent()) {


// Select one of the cards
     if (  mfrc522.PICC_ReadCardSerial()) {



  // Dump debug info about the card; PICC_HaltA() is automatically called
         mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
         Keyboard.print(mfrc522.uid);
    }
  }
}

这就是编译器所说的

note:   no known conversion for argument 1 from 'MFRC522::Uid' to 'const Printable&'
exit status 1

有谁知道该怎么做?

4

1 回答 1

0

我相信您面临的问题是您正在尝试打印一个十六进制数字,MFRC522::Uid例如00 00 00 00while the keyboard.print()only accept或根据:Arduino.cc我在这里找到了以下代码片段。我相信它可能会解决您的问题。它应该写:.charintstring"Card UID: 00 00 00 00"

Serial.print("Card UID:");    //Dump UID
for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
} 

注意:如果您正在使用Keyboard.print()我相信您需要Keyboard.begin()在您的设置方法中使用。

于 2021-05-30T00:06:08.860 回答