can someone help me with the format of an IF statement please.

Within the program I am trying to convert to read and understand RFID’s I have

  for ( i = 0; i < 4; i++) {  //
    readCard[i] = mfrc522.uid.uidByte[i];
    Serial.print(readCard[i], HEX);

this reads the plastic tally and loads the four bit information into readCard
it also shows the number in the monitor (in HEX).

I can successfully get the display to do something if it sees a card but what I would like to do is get it to do different things for different cards, to do this I need to be able to recognise this number.

One card shows the HEX number as 9577A6A5. I have tried all forms of

if (readCard[]==9577A6A5)
do something;

that I can think of. Usually I get expected primary expression before ‘[’ token
is it possible to do it this way or am I missing something?

thanks.

I have tried to make a new array

byte recogCard[4]{123,234,345,456};

with just any old number in for now to see if it works
and changed the if statement to

if (readCard[]==recogCard[1])

Have you tried?
0x9577A6A5

0x9577A6A5 = 2,507,646,629
Look up the 'type' needed.

I don't need the {}'s if there is only one line of instruction do I ?

It doesnt seem to get as far as looking at the number, it seems to crash with the readCard part but I willl try that.

No, changing the right side to 0x9577A6A5 makes no difference to the error.

When you want to specify a numeric constant in hex you have to tell the compiler that you are doing so. Otherwise it doesn't expect to see letters in your number! To do that you prefix the hex with '0x'. Your hexadecimal constant would be 0x9577A6A5. Since it contains four bytes (32 bits) you can store it in an unsigned long int. To convert readCard from a byte array to an unsigned long int you can tell the compiler that what it thinks is the address of a byte is actually the address of an unsigned long int:

const unsigned long recogCard = 0x9577A6A5;

    if (*((unsigned long *)readCard) == recogCard) {
         // The card was detected
    }

'readCard' without the square brackets is the ADDRESS of the first byte of the byte array

'(unsigned long *)' is a 'cast' that tells the compiler to ignore what it knows about the value and treat it as a pointer to an unsigned long int. (the 'int' is implicit).

The '*' in front of it all is the 'dereference' operator that tells the compiler you want the CONTENTS of the variable pointed to by the pointer.

Thank you John. I have been a while because I have been trying to get that to work
I put the first line at the top of my program and altered things to the code below.
For some reason lcd.print(*((unsigned long *)readCard)); prints nothing and the program fails to see the number of the card.

void granted (int setDelay) {
         lcd.setCursor(0,0);
     //    if ((readCard[i])==(recogCard[0]))
      //    if (readCard[]==0x9577A6A5)
       if (*((unsigned long *)readCard) == recogCard) 
           lcd.print(" Hi Bob, Please pass");
         else
           lcd.print("Welcome, Please pass");
         lcd.setCursor(0,3);
         lcd.print(*((unsigned long *)readCard));
         lcd.setCursor(0,4);
         lcd.print(recogCard,HEX);  
         delay (2000);

but it adds a '29' to the end of the forth line of my display when I have the setCursor 0,3 and readCard lines trying to print to the lcd? I assume this is not related directly?

to print the card on the screen I have to do

 for ( i = 0; i < 4; i++) {  //
    readCard[i] = mfrc522.uid.uidByte[i];
    Serial.print(readCard[i], HEX);

Does this mean the information is going and staying in the array?

I think I have found it, it is reading the array readCard from the wrong end
The readCard is A5A67795 and the recogcard is 9577A6A5.

My lcd.setCursors should have been 0,2 and 0,3 not 0,3 and 0,4

I altered the const unsigned long recogCard = 0x9577A6A5;
to const unsigned long recogCard = 0xA5A67795;
and it works fine.
I want to now find if there is a way of reading the card and using it instead of putting the first line in for each card.
Thank you John.

readCard[i] = mfrc522.uid.uidByte[i];

Yes, you are copying four bytes from one array to another.

My guess is that 'uid' is a union: one variable with different aspects. The uidByte aspect is an array of four bytes. There is probably another aspect called something like 'uidLong' or 'uidInt32' that has the 32 bits as a single value. If that is the case you could replace the loop with:

    Serial.print(mfrc522.uid.uidLong, HEX);

and use the comparison

if (mfrc522.uid.uidLong==0x9577A6A5) {

to detect a particular card.