Skip to content

Instantly share code, notes, and snippets.

@AungWinnHtut
Created September 17, 2018 11:19
Show Gist options
  • Save AungWinnHtut/2f44387f5d41b77d181b67d51208e322 to your computer and use it in GitHub Desktop.
Save AungWinnHtut/2f44387f5d41b77d181b67d51208e322 to your computer and use it in GitHub Desktop.
///////////////////
int getID() {
// Getting ready for Reading PICCs
if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
return 0;
}
if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue
return 0;
}
// There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC
// I think we should assume every PICC as they have 4 byte UID
// Until we support 7 byte PICCs
Serial.println("Scanning PICC's UID.........");
//delay(2000);
for (int i = 0; i < mfrc522.uid.size; i++) { //
readCard[i] = mfrc522.uid.uidByte[i];
Serial.print(readCard[i], HEX);
}
Serial.println("");
mfrc522.PICC_HaltA(); // Stop reading
return 1;
}
String readRFID() {
do {
successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0
Serial.println("no card");
//if (programMode) {
// Program Mode cycles through RGB waiting to read a new card
//}
//else {
//}
}
while (!successRead); //the program will not go further while you not get a successful read
if (successRead)
{
successRead = 0;
String content = "";
byte letter;
for ( byte i = 0; i < mfrc522.uid.size; i++ ) {
content.concat(String(readCard[i], HEX));
}
content.toUpperCase();
funLCDprint("Card Read", 0, 0, 0, 1);
funLCDprint(content, 0, 1, 1000, 0);
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
return content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment