RFID标签切换LED开关

问题描述 投票:0回答:1

我有这个示例代码(MFRC522-DumpInfo-https://github.com/miguelbalboa/rfid)-正常工作,在串行监视器中,我可以看到“卡UID”。

我正在尝试2天(只是初学者),但不知道如何“提取”卡UID,因此当给出正确的UID RFID标签时,我可以通过if语句来打开LED。+当再次出现时,LED将熄灭。 (带RFID的拨动开关)。

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_PIN          10         // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

void setup() {
    Serial.begin(9600);     // Initialize serial communications with the PC
    while (!Serial);        // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
    SPI.begin();            // Init SPI bus
    mfrc522.PCD_Init();     // Init MFRC522
    delay(4);               // Optional delay. Some board do need more time after init to be ready, see Readme
    mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
    Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}

void loop() {
    // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
    if ( ! mfrc522.PICC_IsNewCardPresent()) {
        return;
    }

    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial()) {
        return;
    }

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

将感谢您的帮助,祝您编程愉快:)

c arduino switch-statement nfc rfid
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.