Help with understanding for/if statement in RFID sketch


i purchased 2 rc522 rfid reader/writers. i've been playing them 3 weeks , have done many hours of research , reading in attempt understand programming. there many youtube videos , few code examples, little explanation. seek assistance. found base code below through 1 of youtube videos, , i'm able use it, edit it, , make work, don't understand critical parts of it.

code: [select]
 
   #include <spi.h>
#include <mfrc522.h>
#define ss_pin 10
#define rst_pin 9
mfrc522 mfrc522(ss_pin, rst_pin);
int greenled = 6;
int redled = 4;

void setup() {
spi.begin();
mfrc522.pcd_init();
        pinmode(greenled,output); //green led
        pinmode(redled,output); //red led
        serial.begin(9600);       
}

void loop() {
        serial.println("scan rfid card now.");
if ( ! mfrc522.picc_isnewcardpresent()) {
return;
}

// select 1 of cards
if ( ! mfrc522.picc_readcardserial()) {
return;
}
       
        byte myid[4] ={0x04,0x00,0x41,0x82};   //card b
        byte myid2[4] ={0x04,0x26,0xa5,0x82};  //card a
       
        byte isok= 0;
        byte isok2= 0;
       
        (byte = 0; < mfrc522.uid.size; i++) {
          if (mfrc522.uid.uidbyte[i]==myid[i]) {
             isok= isok+1;
          }
        }
       
        (byte = 0; < mfrc522.uid.size; i++) {
          if (mfrc522.uid.uidbyte[i]==myid2[i]) {
             isok2= isok2+1;
          }
        }

        if (isok==4){
          serial.println("hello emma! welcome world!");
          digitalwrite(greenled,high);
           delay(2000);
           digitalwrite(greenled,low);
           delay(2000);
           digitalwrite(greenled,high);   
           delay(2000);
           digitalwrite(greenled,low);
           delay(2000);
           }
           
           
           if (isok2==4){
           serial.println("hello benjamin. prepare robot invasion!");
           delay(250);
           digitalwrite(greenled,high);       
           delay(250);
           digitalwrite(greenled,low);
           delay(250);
           digitalwrite(greenled,high);   
           delay(250);
           digitalwrite(greenled,low);
           delay(250);
           }
       
       
           else if (isok < 4){
            serial.println("denied!");
            digitalwrite(redled,high);
            delay(3000);
            digitalwrite(redled,low);
            delay(2000);
           }
           
}


question 1)  know the  byte myid[4] = {0x04,0x00,0x41,0x82};  rfid card's unique id. can change , register fine. don't understand [4]. bracket 4 used do? , why byte myid2 use [4]?

question 2) 2 for/if statements doing? correction, believe sketch matching unique id of card unique id found in myid[4], don't understand how. i'm not sure how read section aloud or explain it. in if statements there part adds 1 isok variable. i'm not sure why happening.

thank in advance in explaining how/why functions. know can continue use , away it, i'd understand it.


question 1)  know the  byte myid[4] = {0x04,0x00,0x41,0x82};  rfid card's unique id. can change , register fine. don't understand [4]. bracket 4 used do? , why byte myid2 use [4]?


the array contains 4 elements, in case bytes.

quote

question 2) 2 for/if statements doing? correction, believe sketch matching unique id of card unique id found in myid[4], don't understand how. i'm not sure how read section aloud or explain it. in if statements there part adds 1 isok variable. i'm not sure why happening.

thank in advance in explaining how/why functions. know can continue use , away it, i'd understand it.


it testing matches of arrays , counting them.  if 4 matches, successful scan.  in awkward fashion.

don't beat up... code not written , has lot difficulty understanding it.


Arduino Forum > Using Arduino > Programming Questions > Help with understanding for/if statement in RFID sketch


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support