How to make things easier?

Hi,

I have a bit of a problem, i try to work on a project with a rc522 rfid. i use a lib from a chineese guy, everything works, it read the cards...... and i compair it with "good" or "bad" cards.. of an array?. This works.

Like this, i compair it in an if statement, but this is not realy handy, if i loose a card or want to add a card i have to write an new if statement to add/del a cardnr.

How can i made it easier to add/del cards?

I am a bit of a n00b on arduino, i use a uno with a RFID RC522 SPI. i have a Internet shield, so i (if needed) get the "good" card out a database... but first things first.

Code 1:

status = MFRC522_Anticoll(str);
        memcpy(serNum, str, 5);
                if (status == MI_OK)
        {

                        Serial.println("\nKaart nummer : ");
            Serial.print(serNum[0],DEC);
                        Serial.print(" , ");
            Serial.print(serNum[1],DEC);
                        Serial.print(" , ");
            Serial.print(serNum[2],DEC);
                        Serial.print(" , ");
            Serial.print(serNum[3],DEC);
                        Serial.print(" , ");
            Serial.print(serNum[4],DEC);
                        Serial.println(" ");

                     
                        if(((serNum[0] == 7 && serNum[1] == 28) && (serNum[2] == 161 && serNum[3] == 181) && (serNum[4] == 15))) { 
// this is the number of the card that is known, compair to the array
                          Serial.println("Hallo John");
                          Serial.print("Some action can put in here");
                          digitalWrite(ledPinGeel, LOW);
                        
                        } else if(((serNum[0] == 48 && serNum[1] == 32)) && ((serNum[2] == 97 && serNum[3] == 116)) && (serNum[4] == 5)) { 
// this is the number of the card that is known, compair to the array
                          Serial.println("Hallo Katinka");
                          Serial.print("Some action can put in here");
                          digitalWrite(ledPinGeel, LOW);
                        }
                          else {
                           Serial.print("Not a known card dude! \n"); 
                           digitalWrite(ledPinRood, LOW);
                           
                          }
                        
                                 delay(1000);
        }

This is an ordinary programming question and I have suggested to the Moderator to move it to the programming section of the Forum.

You need to post your complete code rather than a short snippet.

You also need to tell us what procedure you would like to use to add additional RFID cards

...R

#define cardCount 3
char validCards[cardCount][5]={"1234","8736","5022"};
...
...
...
...

void checkCard(char* serNum)
{
for (int n=0;n<cardCount;n++)
  if(strcmp(serNum,validCards[n])==0)
    {Serial.println("The force is strong with this one");
     return;
    }
Serial.println("These are not the droids you're looking for");
}

If you want to add cards on the fly you will need to write them into some form of memory. You can't write into FLASH so that leaves SRAM, EEPROM, or something external. SRAM will loose its contents if power is interrupted. The built-in EEPROM is very limited in size. You can use an SD card, external FRAM or EEPROM, or A TCP/IP connection.