#include <SPI.h>
#include <MFRC522.h>
MFRC522 mfrc522(10, 9);
void setup() {
Serial.begin(9600);
delay(500);
}
void loop() {
SPI.begin();
mfrc522.PCD_Init();
if ( ! mfrc522.PICC_IsNewCardPresent()) return;
if ( ! mfrc522.PICC_ReadCardSerial()) return;
Serial.print("Codice Card: ");
VectorPrint(mfrc522.uid.uidByte, 4);
Serial.println();
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
}
void VectorPrint(byte *x, byte dv) {
char ch[2];
for (byte i = 0; i < dv; i++) {
DectoHex(x[i], ch);
Serial.print(ch[0]);
Serial.print(ch[1]);
}
}
void DectoHex(byte z, char ch[2]) {
byte nb;
nb = z / 16;
if (nb>9){nb = nb + 55;}
else {nb = nb + 48;}
ch[0] = char(nb);
nb = z % 16;
if (nb>9){nb = nb + 55;}
else {nb = nb + 48;}
ch[1] = char(nb);
}