Hi everyone. I hope someone can help me.
I'm using a Mega with RC522, and this happens:
I use a tag, it reads the right serial (e.g. AA:BB:CC:DD). Then I use a second tag and sometimes it gives me the correct value (e.g. 00:11:22:33), but often it gives me the previous tag serial (AA:BB:CC:DD). After a few attempts, it finally gives me the right one (00:11:22:33).
I really can't find what's wrong and i'd be grateful if someone could shed some light.
Here's the code:
if (RC522.PICC_IsNewCardPresent()) {
RC522.PICC_ReadCardSerial();
String strID = "";
for (byte i = 0; i < 4; i++) {
strID +=
(RC522.uid.uidByte[i] < 0x10 ? "0" : "") +
String(RC522.uid.uidByte[i], HEX) +
(i != 3 ? ":" : "");
}
String seriale = strID;
if (seriale != "0"){
for(h=0; h<=numerogiocatori -1;h++){
if (seriale == seriali[h]) {
lcd.clear();
lcd.print("Saldo Gioc. ") ;
lcd.print(h + 1) ;
Serial.print("tag ID: ");
Serial.print(seriale);
Serial.print(" . ");
lcd.setCursor(0, 1);
lcd.print(totaledenaro[h]) ;
delay(1500);
lcd.clear();
lcd.print("Importo");
lcd.setCursor(0, 1);
}
}
}
}
Thanks to anyone willing to help!