first thankyou all for your answers.
how can I use program memory?
here is my code:
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9
#define SS_PIN 10
MFRC522 mfrc522(SS_PIN, RST_PIN);
String read_rfid;
int lock = 7; // relay output.
#define ARRAYSIZE 50
String ID_num[ARRAYSIZE] = { "bcc0f1c3", "821a7d39", "4924887c", "b976499", "d2bb3345", "82959144", "1280b939", "b2a42544", "c2b93044", "92787344",
"79417d", "32d77e44", "f2283545", "499927c", "894ee87c", "122a4945", "59e9a07c", "127e8e44", "c915687c", "92f17d44",
"426d9244", "1265dd39", "22d4144", "29d79d7c", "e22a7644", "2748944", "629b9144", "d9ea9b7c", "19194f7c", "29f15a7c",
"62113044", "69b26b7c", "e926b57c", "522c3e44", "29f04e7c", "e94a807c", "79f2797c", "32767644", "69f9c37c", "d2b67a39",
"f2b53244", "62ea3645", "32b63644", "f95687c", "22833d45", "c26c7644", "12bb8039", "f2c62c45", "f9147f4d", "2261fa39" }; //my known cards
int Counters[ARRAYSIZE] ;
int flag = 1 ; //for initialize the counters only once in the loop function
/*
* Initialize.
*/
void setup() {
Serial.begin(9600);
while (!Serial);
SPI.begin();
mfrc522.PCD_Init();
pinMode(lock, OUTPUT);
}
void dump_byte_array(byte *buffer, byte bufferSize) {
read_rfid="";
for (byte i = 0; i < bufferSize; i++) {
read_rfid=read_rfid + String(buffer[i], HEX);
}
}
//_______________________________________________________________________________________
//this function gets the card counter, countown 1 entry from it, open the gate and return the updated counter.
// in case of a master tag ,( x == -1 ) , it will just open the gate.
int Open_Door_RFID ( int x ) {
if ( x > 0 ) // regular user
{
x-- ;
digitalWrite (lock , HIGH); // opening the gate
delay (500);
digitalWrite (lock , LOW);
Serial.println(x);
// delay (7000);
}
else if ( x == -1 ) // master user
{
digitalWrite (lock , HIGH); // opening the gate
delay (500);
digitalWrite (lock , LOW);
}
return x;
}
//_______________________________________________________________________________________
void loop() {
//first we initialize the counters array
if (flag == 1) { //for initializing only once
int k;
for ( k = 0 ; k < 10 ; k++ ){ // the first 10 tags are master
Counters[k]=-1;
}
for ( k = 10 ; k < ARRAYSIZE ; k++ ){ // the othr tags has 30 entries
Counters[k]=30;
}
}
flag = 0;
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
return;
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
return;
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println(read_rfid);
for (int i =0; i< ARRAYSIZE; i++){ // compare the readen card to the list
if (read_rfid == ID_num[i] ) {
Counters[i]=Open_Door_RFID(Counters[i]) ;
}
}
}