I needed an algorithm to figure out if the card was avaliable . I've gone through the past discussions and honestly I couldn't understand what the solution was. I am attaching the solution I found below. it seems to be working fine. I just want to share.
Relevant Code:
byte ReadAttemp=0;
bool CardState=false;
void loop()
{
if (Card_Available())
{
// do it something...
}
}
bool Card_Available()
{
ReadAttemp=0;
while (1)
{
ReadAttemp++; // +1 oldu, +2 oldu ise kart yok...
if (ReadAttemp>2)
{
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
if (ReadAttemp>3)
{
//Serial.println("NO CARD !");
//digitalWrite(LED,LOW);
CardState= false;
break;
}
}
if (mfrc522.PICC_IsNewCardPresent() and mfrc522.PICC_ReadCardSerial())
{
//Serial.println("CARD !");
ReadAttemp=0;
//digitalWrite(LED,HIGH);
CardState = true; //return true... any function can work.
break;
}
}
return CardState;
}
I needed an algorithm to figure out if the card was avaliable . I've gone through the past discussions and honestly I couldn't understand what the solution was. I am attaching the solution I found below. it seems to be working fine. I just want to share.
Relevant Code: