47 lines
995 B
C++
47 lines
995 B
C++
/**
|
|
* ...
|
|
*
|
|
* Author: Alexander Popov
|
|
* License: Unlicense
|
|
*/
|
|
|
|
#include <SPI.h>
|
|
#include <MFRC522.h>
|
|
|
|
#define SS_PIN 7
|
|
#define RST_PIN 9
|
|
|
|
MFRC522 rfid(SS_PIN, RST_PIN);
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
SPI.begin();
|
|
rfid.PCD_Init();
|
|
|
|
Serial.println("Tap RFID/NFC Tag on reader.");
|
|
}
|
|
|
|
void loop() {
|
|
// new tag is available
|
|
if (rfid.PICC_IsNewCardPresent()) {
|
|
// NUID has been readed
|
|
if (rfid.PICC_ReadCardSerial()) {
|
|
MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
|
|
|
|
Serial.print("RFID/NFC Tag Type: ");
|
|
Serial.println(rfid.PICC_GetTypeName(piccType));
|
|
|
|
// print NUID in Serial Monitor in the hex format
|
|
Serial.print("UID:");
|
|
for (int i = 0; i < rfid.uid.size; i++) {
|
|
Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
|
|
Serial.print(rfid.uid.uidByte[i], HEX);
|
|
}
|
|
Serial.println();
|
|
|
|
rfid.PICC_HaltA(); // halt PICC
|
|
rfid.PCD_StopCrypto1(); // stop encryption on PCD
|
|
}
|
|
}
|
|
}
|