键盘打印 UID MFRC522 Arduino Leonardo

Keyboard print UID MFRC522 Arduino Leonardo

我想用 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

有人知道怎么做吗?

我相信你面临的问题是你试图打印一个 MFRC522::Uid 这是一个十六进制数字,例如 00 00 00 00keyboard.print() 只接受 charintstring 根据:Arduino.cc. I found the following code snippet here。我相信它可能会解决您的问题。它应该写成:"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()