-
-
Save parzibyte/bff603dc879b7eb7da95d804c213f0bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void loop() | |
{ | |
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle. | |
if (!reader.PICC_IsNewCardPresent()) | |
{ | |
return; | |
} | |
// Select one of the cards. This returns false if read is not successful; and if that happens, we stop the code | |
if (!reader.PICC_ReadCardSerial()) | |
{ | |
return; | |
} | |
// At this point, the serial can be read. We transform from byte to hex | |
String serial = ""; | |
for (int x = 0; x < reader.uid.size; x++) | |
{ | |
// If it is less than 10, we add zero | |
if (reader.uid.uidByte[x] < 0x10) | |
{ | |
serial += "0"; | |
} | |
// Transform the byte to hex | |
serial += String(reader.uid.uidByte[x], HEX); | |
// Add a hypen | |
if (x + 1 != reader.uid.size) | |
{ | |
serial += "-"; | |
} | |
} | |
// Transform to uppercase | |
serial.toUpperCase(); | |
Serial.println("Read serial is: " + serial); | |
// Halt PICC | |
reader.PICC_HaltA(); | |
// Stop encryption on PCD | |
reader.PCD_StopCrypto1(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment