【问题标题】:Keyboard print UID MFRC522 Arduino Leonardo键盘打印 UID MFRC522 Arduino Leonardo
【发布时间】:2021-08-17 17:43:16
【问题描述】:

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

有人知道怎么做吗?

【问题讨论】:

    标签: c++ arduino atmega32


    【解决方案1】:

    我相信您面临的问题是您正在尝试打印一个MFRC522::Uid,它是一个十六进制数字,例如00 00 00 00,而keyboard.print() 只接受charintstring根据:Arduino.cc。我找到了以下代码 sn -p 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()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-05
      • 1970-01-01
      • 2022-11-10
      • 2014-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多