RFID reader Hex data UID - convert and compare

Hello Forum!

Im doing a school-project with RFID-tagged Records that trigger different Videos on a screen.
Setup:
Records with RFID-tags
+
RecordPlayer hacked with RFID Reader
+
Arduino Leonardo (sketch: tags assigned to different key-strokes)
+
via USB to Computer
+
HTML5 website key-strokes link to different websites with video

Now my problem:
I have working the RFID hardware and I am reading in the UID (SerialNumber) of the tags and print them to the SerialMonitor.

But Im stuck for now: how to get this number, store it, convert it and compare it in a conditional statement?
(from mySerial.read to ... an array?? ...an if-statement )

I used the following snippet in an other Project to convert an array of HEX numbers into comparable numbers for an if-statement

uint8_t uid[] = { 0, 0, 0, 0  };    
uint32_t cardidentifier = 0;

    cardidentifier = uid[3];
    cardidentifier <<= 8; 
    cardidentifier |= uid[2];
    cardidentifier <<= 8; 
    cardidentifier |= uid[1];
    cardidentifier <<= 8; 
    cardidentifier |= uid[0];

But I have no clue how to get there...
Here is the code im using in the moment:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10,11);

unsigned char command, devnull;
unsigned int returnLength;

void setup()  
{
  Serial.begin(9600);

  Serial.println("Waiting for Card\n");
  mySerial.begin(9600);

   mySerial.write(0x02); //Send the command to RFID, please refer to RFID manual
}

void loop()
{
  if (mySerial.available()) {
    Serial.print("\n\rCARD SERIAL: ");
    for (unsigned int i=0; i<4 ;i=i){
      if (mySerial.available()) {
        Serial.print(mySerial.read(),HEX); //Display the Serial Number in HEX
        i++;
      }
    }
    mySerial.write(0x02); //Send the command to RFID, please refer to RFID manual
  }
}       

/*

void Get_Reply() {
  while (!mySerial.available());
  devnull = mySerial.read();
  while (!mySerial.available());
  returnLength = mySerial.read() - 1;

  for (unsigned int i=0;i< returnLength;i=i){
    //Serial.print("2"); 
    if (mySerial.available()) {
      //Serial.print("\n\ri is: ");Serial.print(i);Serial.print(" ");
      Serial.print(mySerial.read(),HEX); //Display the Serial Number in HEX
      Serial.print(" ");
      i++;
      
    }
  }
}

*/

Thanks in advance for your support!
lg
Markus

Hello Forum!

Problem solved...
This works for me:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10,11);

unsigned char command, devnull;
unsigned int returnLength;

int uid[4];
int cardidentifier;


void setup()  
{
  Serial.begin(9600);

  Serial.println("Waiting for Card\n");
  mySerial.begin(9600);

  mySerial.write(0x02); //Send the command to RFID, please refer to RFID manual
}

void loop()
{
  if (mySerial.available()) {
    Serial.print("\n\rCARD SERIAL: ");
    for (unsigned int i=0; i<4 ;i=i){
      if (mySerial.available()) {
        //Serial.print(mySerial.read(),HEX); //Display the Serial Number in HEX
        uid[i]= mySerial.read();
        i++;
      }
    }

    for (uint8_t i=0; i < 4; i++) 
    {
      Serial.print(uid[i], HEX);
    }

    uint32_t cardidentifier = 0;

    cardidentifier = uid[3];
    cardidentifier <<= 8; 
    cardidentifier |= uid[2];
    cardidentifier <<= 8; 
    cardidentifier |= uid[1];
    cardidentifier <<= 8; 
    cardidentifier |= uid[0];

    Serial.println("");

    Serial.println(cardidentifier);

    if(cardidentifier == 87391397 ) {
      Keyboard.write('a');
      Serial.println("YO!");
      delay(2000);
    }

    //delay(2000);

    mySerial.write(0x02); //Send the command to RFID, please refer to RFID manual
  }


}

For the records:
Im using an elechouse RFID reader, based on a RC522 connected via UART.
Arduino Leonardo is acting as a keybord - puts out different keystrokes for different RFID-Tags.

  if (mySerial.available()) {
    Serial.print("\n\rCARD SERIAL: ");
    for (unsigned int i=0; i<4 ;i=i){
      if (mySerial.available()) {
        //Serial.print(mySerial.read(),HEX); //Display the Serial Number in HEX
        uid[i]= mySerial.read();
        i++;
      }
    }

That code leaves a lot to be desired. Using a for loop that way is just bizarre. It is a for loop pretending to be a while loo. A while statement would make a lot more sense.

byte i=0;
while(i<4)
{
   if(mySerial.available() > 0)
   {
      uid[i++] = mySerial.read();
   }
}

You don't have a mySerial attached to the Arduino, do you? Why doesn't the instance name reflect what IS attached?

Im using a CRC function to convert the serial number to an integer. This way i'm pretty shure that all card numbers are unique. And its easy to store and compare them.