Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arduino NFC PN532_Arduino_Nfc_Spi - Fatal编程技术网

Arduino NFC PN532

Arduino NFC PN532,arduino,nfc,spi,Arduino,Nfc,Spi,你好,我正在尝试制作一个程序来比较NFC标签ID,我非常习惯Arduino,但我不习惯SPI编程 我找了很多,但我真的不知道我到底需要什么 我正在尝试匹配NFC标记ID和变量NFC1 有人能帮我吗?求你了 我只需要一些信息/帮助来让if语句起作用 #include <PN532.h> #include <SPI.h> //SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK) /*Chip select pin can be conn

你好,我正在尝试制作一个程序来比较NFC标签ID,我非常习惯Arduino,但我不习惯SPI编程

我找了很多,但我真的不知道我到底需要什么

我正在尝试匹配NFC标记ID和变量NFC1

有人能帮我吗?求你了

我只需要一些信息/帮助来让if语句起作用

#include <PN532.h>
#include <SPI.h>

//SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK)

/*Chip select pin can be connected to D10 or D9 which is hareware optional*/
/*if you the version of NFC Shield from SeeedStudio is v2.0.*/
#define PN532_CS 10
PN532 nfc(PN532_CS);
#define  NFC_DEMO_DEBUG 1

int BUZZER = 6;
uint32_t NFC1 = 3795120787;
int NFC2 = 3262404755;
int NFC3 = 46356883;
int NFC4 = 35320979;
int NFC5 = 3257334163;

void setup(void) {

pinMode(BUZZER, OUTPUT);
#ifdef NFC_DEMO_DEBUG
Serial.begin(9600);
Serial.println("Hello!");
#endif
nfc.begin();

uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
#ifdef NFC_DEMO_DEBUG
Serial.print("Didn't find PN53x board");
Serial.print("");
#endif
while (1); // halt
}
#ifdef NFC_DEMO_DEBUG
// Got ok data, print it out!
Serial.print("Found chip PN5"); 
Serial.println((versiondata>>24) & 0xFF, HEX);
/*Serial.print("Firmware ver. "); 
Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print('.'); 
Serial.println((versiondata>>8) & 0xFF, DEC);
Serial.print("Supports "); 
Serial.println(versiondata & 0xFF, HEX);*/
#endif
// configure board to read RFID tags and cards
nfc.SAMConfig();
}


void loop(void) {
uint32_t id;
// look for MiFare type cards
id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);

if (id != 0) {
#ifdef NFC_DEMO_DEBUG
Serial.println("");
Serial.print("Card #"); 
Serial.println(id);
analogWrite(BUZZER, 50);
delay(100);
analogWrite(BUZZER, 0);
delay(1000);
#endif
//char ch = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);

if(NFC1 = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A)){

    analogWrite(6, 255);
    delay(250);
    analogWrite(6, 0);
  /*analogWrite(BUZZER, 50);
  delay(50);
  analogWrite(BUZZER, 0);
  delay(50);
  analogWrite(BUZZER, 50);
  delay(50);
  analogWrite(BUZZER, 0);*/}

  else {
    analogWrite(5, 255);
    delay(250);
    analogWrite(5, 0);
  /*analogWrite(BUZZER, 50);
  delay(100);
  analogWrite(BUZZER, 0);
  delay(100);
  analogWrite(BUZZER, 50);
  delay(100);
  analogWrite(BUZZER, 0);
  delay(100);
  analogWrite(BUZZER, 50);
  delay(100);
  analogWrite(BUZZER, 0);*/}
  }
   }

常见错误和编译器本可以帮助您

更改此行:

uint32_t NFC1 = 3795120787;
const uint32_t NFC1 = 3795120787;
关于这一行:

uint32_t NFC1 = 3795120787;
const uint32_t NFC1 = 3795120787;
您现在将得到一个编译器错误,这将导致您执行:o

这行需要一个==,而不是一个=。不是这个:

if(NFC1 = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A)){   / doh!
这:

请注意,这是一个常见的键入错误及其原因

if(1 == somevar)  // is superior to

if(somevar == 1)  // something that seems exactly the same
因为编译器会告诉你

if(1 = somevar)  // no, you can't assign to a constant

if(somevar = 1)  // okay, whatever you want boss
这个建议来自于编写可靠的代码、Maguire和Moore,对我很有帮助。

我明白了!我从ifNFC1==nfc.readPassiveTargetIDPN532\u MIFARE\u ISO14443A改为ifNFC1==id,现在可以使用了,非常感谢您的帮助!