我无法在我的 arduino 项目上解决这个问题。我在 vscode 上使用 Platformio。
我想使用 MFRC522_I2C 库来读取 rfid 徽章,因此我创建了一个类来使用库方法。
该库可以在这里找到:https ://github.com/arozcan/MFRC522-I2C-Library
这是我的代码:
主要.cpp:
#include <Arduino.h>
#include "rfid/Rfid.hpp" // my rfid class
Rfid _rfid;
void setup()
{
Serial.begin(115200);
_rfid.setupRfid();
}
void loop()
{
_rfid.rfidLoop();
}
Run Code Online (Sandbox Code Playgroud)
射频识别.cpp:
#include "Rfid.hpp"
Rfid::Rfid(/* args */)
{
}
Rfid::~Rfid()
{
}
void Rfid::setupRfid()
{
_rfidReader.PCD_Init();
}
void Rfid::rfidLoop()
{
// here is my code to read the rfid
}
Run Code Online (Sandbox Code Playgroud)
射频识别.hpp:
#ifndef _RFID_HPP_
#define _RFID_HPP_
#include "../lib/rfidReader/MFRC522_I2C.h" // the MFRC522 library
MFRC522 _rfidReader(0x28);
class …Run Code Online (Sandbox Code Playgroud) c++ arduino multiple-definition-error visual-studio-code platformio