1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>
// If using the breakout with SPI, define the pins for SPI communication. //
#define PN532_SCK (13)
#define PN532_MOSI (11)
#define PN532_SS (10)
#define PN532_MISO (12)
Adafruit_PN532 nfc(PN532_SS);
void setup() {
Serial.begin(115200); // Ouvre le port série et fixe le debit de communication à 115200 bauds (unité de mesure)
nfc.begin(); // Démarrage de la communication NFC
nfc.SAMConfig();
}
void loop() {
//lectureBadge();
//uint32_t cardId = lectureBadge();
String cardId = lectureBadgeString();
Serial.println(cardId);
//envoiTag();
}
Et Voila ma partie renvoie fonction (renvoie numéro ou tag) :
String lectureBadgeString() {
uint8_t success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
char cardIdTableau[8];
String uidString = "";
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
sprintf(cardIdTableau, "%x%x%x%x", uid[0], uid[1], uid[2], uid[3]);
}
uidString = cardIdTableau;
return uidString;
} |
Partager