RFID compare

hello every one
pleas i need a help , i’m using RFID sensor with 4 card i need to make a compare between them .
that each card do some thing when i read it
so how i can do the compare between 4 , i found a code with 2 card comparing but not 4
so pleas if any one know how i can do this

// Make your Antenna pins "2 pins Only) to top right
// Top Left: 2nd pin to 5V and 3rd pin to Ground
// Bottom Left: 1st pin to Arduino Pin 2


#include <SoftwareSerial.h>
SoftwareSerial RFID(2, 3); // Assigned digital pins 2 & 3 as RX and TX
int data1 = 0;
int ok = -1;
int yes = 13;        // Defining Yes as number 13, Used later for leds  
int no = 12;         // Defining Yes as number 13, Used later for leds

// Make Arays
int tag1[14] = {2,56,53,48,48,48,57,49,66,69,48,55,55,3};      // Enter Card Code
int tag2[14] = {2,52,48,48,48,56,54,67,54,54,66,54,66,3};      // Enter Card Code
int newtag[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0};               // Empty for new read card value; used for read comparisons


void setup()
  {
    RFID.begin(9600); // start serial to RFID reader
    Serial.begin(9600); // start serial to PC 
    pinMode(yes, OUTPUT); // Make pin 13 output
    pinMode(no, OUTPUT);  // Make pin 12 output
  }

void loop()
{  readTags();
}

//////////Functions to be called////////////

    ///// Read Tags /////
        void readTags()
            {  ok = -1;
               if (RFID.available() > 0) // read tag numbers 
                  {  delay(100); // needed to allow time for the data to come in from the serial buffer.
                     for (int z = 0 ; z < 14 ; z++) // read the rest of the tag
                        {  data1 = RFID.read();
                           newtag[z] = data1;
                        }
                     RFID.flush(); // stops multiple reads
                     checkmytags();      // do the tags match up?
                  }
      
              if (ok > 0) // if matched then do the following
                {    Serial.println("Accepted");
                     digitalWrite(yes, HIGH);
                     delay(1000);
                     digitalWrite(yes, LOW);     // turn off the led to be ready for the next read
                     ok = -1;                    // reset ok to -ve 1 which means no card read now to be ready for the next one
                } 
              else if (ok == 0) // if we didn't have a match
                {   Serial.println("Rejected");
                    digitalWrite(no, HIGH);
                    delay(1000);
                    digitalWrite(no, LOW);
                    ok = -1;
                    }
            }
    ///// EOF Read Tags ///// Note: it calls The function Check my tags

    ///// check Tags and set ok /////
          void checkmytags() // compares each tag against the tag just read
          { ok = 0; // this variable helps decision-making,
              // if it is 1 we have a match, zero is a read but no match,
              // -1 is no read attempt made
              // Note: You should compare the new tag to every tag saved at Code Start
            if (comparetag(newtag, tag1) == true)   // call comparetag function and send newtag & tag 1
              { ok++;
              }
            if (comparetag(newtag, tag2) == true)  // call comparetag function and send newtag & tag 2
              { ok++;
              }
          }
    ///// EOF check Tags and set ok value ///// Note: it calls the function Compare tags
      
    ///// Compare Tags /////
      boolean comparetag(int array1[14], int array2[14]) // This Function Returns Boolean and takes values and put in array form having integer values
          {  boolean result = false;   // Set a variable called "result" with a bloolean type and initial value is false
             int temp = 0;
             for (int counter = 0 ; counter < 14 ; counter++) // function is proccessed 14 times and the counter value used in the array inside
                {   if (array1[counter] == array2[counter]) // Compare array1[0] to array2[0], 2nd loop: array1[2] to array2[2], 2nd loop: array1[3] to array2[3], ..etc
                        { temp++;                           // if both are equal increase temp by 1
                        }
                }
             if (temp == 14)
                {   result = true;                          // if every array item was similar to the other the total incrementation will be equal 14 so result set to true ( card is simillar )
                }
             return result;
          }
    ///// EOF Compare Tags /////

Can’t you just modify “checkmytags” to compare another two tags?

int tag1[14] = {2,56,53,48,48,48,57,49,66,69,48,55,55,3};

Crazy waste of RAM.

boolean comparetag(byte array1[14], byte array2[14])
{
  for (int counter = 0 ; counter < 14 ; counter++)
  {   
    if (array1[counter] != array2[counter])
      return false;
  }
  return true;        
}

Much simpler.

Looks to me like you make more of these:

int tag2[14] = {2,52,48,48,48,56,54,67,54,54,66,54,66,3};      // Enter Card Code

.... for tag3 and tag4.

Then further in the code you add two more of these:

if (comparetag(newtag, tag1) == true)   // call comparetag function and send newtag & tag 1
              { ok++;
              }
if (comparetag(newtag, tag2) == true)  // call comparetag function and send newtag & tag 2
              { ok++;
              }

.... for tag3 and tag4.

There might be more but that's all I see at first glance.

But as AWOL says, it's inelegant. Imagine if you had 10s or 100s....

Imagine if you had 10s or 100s....

const byte knownTags [N_TAGS][14] = ({2,56,53,48,48,48,57,49,66,69,48,55,55,3},
                                {2,52,48,48,48,56,54,67,54,54,66,54,66,3},

Or just read them straight out of EEPROM.