Save and read string RFID in EEPROM-ArduninoUNO (solved)

Hello everyone and so sorry to the moderators for repeat my question..

I have a RFID-ID20 + ArduinoUNO
I want to read a tag and save it in EEPROM (between 10 to 29)
read a second tag and save it in EEPROM (between 30 to 49)
when my code read a tag saved before in EEPROM must delete this tag only between positions where this tag had been saved before

currently
-if read a tag that before was saved between 30 to 49 my code work fine.
my problem:

  • if read a tag that before was saved between 10 to 29 my code delete the EEPROM between 10 to 49, here must delete only between 10 to 29
#include <EEPROM.h>

char code[15];

int  val = 0; 
int bytesread = 0; 
int led = 13;
int addr = 10;
int addr2 = 30;

byte x= 1;        // (00000001)

void setup() 
  { 
  Serial.begin(9600); 
  pinMode(13, OUTPUT);   
  pinMode(12, OUTPUT);
  } 

void loop() 
{ 
        if(Serial.available() > 0) 
        {                            
          if((val = Serial.read()) == 10) 
                  {     
                    bytesread = 0; 
                            while(bytesread < 15) 
                            {             
                                      if( Serial.available() > 0) 
                                      { 
                                        val = Serial.read(); 
                                        if((val == 10)||(val == 15)) 
                                            {  
                                            break;                        
                                            } 
                                        code[bytesread] = val;          
                                        bytesread++; 
                                      } 
                            }                             
                     Serial.print("tag read: ");
                     Serial.println(code);   //tag1 x2400CC392AFBxxx   tag2 x2400CC572897xxx

                   

                          bool match1 = true;
                          byte offs1=10;
                          bool match2 = true;
                          byte offs2=30;
    //comparation1 value in eeprom with value read-tag
                          for (byte b=2; b<13; b++)
                               {
                                 if (EEPROM.read( b + offs1) != code [b])
                                 {
                                 match1 = false;
                                 break;
                                 }
                               }       
                           if (match1 == true)
                           {
                             Serial.println("ok position1 - tag deleted from position1, EERPOM 10 to 29");
                             digitalWrite(13, HIGH);
                             delay(250);
                             digitalWrite(13, LOW);
                             delay(250);
                             bitWrite(x, 1, 0);
                          //delete EEPROM between 10 to 29
                             for (int i = 10; i < 29; i++)
                             EEPROM.write(i, 0);                          
                           } 
                           
                           else
     
     //comparation2 value in eeprom with value read-tag
                          for (byte b=2; b<13; b++)
                               {
                                 if (EEPROM.read( b + offs2) != code [b])
                                 {
                                 match2 = false;
                                 break;
                                 }
                               }       
                           if (match2 == true)
                           {
                             Serial.println("ok position2 - tag deleted from position2, EERPOM 30 to 49");
                             digitalWrite(12, HIGH);
                             delay(250);
                             digitalWrite(12, LOW);
                             delay(250);
                             bitWrite(x, 2, 0);
                             //delete EEPROM between positions 30 to 49
                             for (int i = 30; i < 49; i++)
                             EEPROM.write(i, 0);                          
                           } 
                           
                           else
                           
                             //bitread position 1
                             if (bitRead(x,1) == 0)
                               {
                                //write 1       
                                  bitWrite(x, 1, 1);
                                 //write in eerpom
                                  for(byte b=0; b<bytesread; b++)
                                  { //addr = start in position 10
                                     EEPROM.write(addr + b, code[b]);
                                  }                     
                                //turn on led pin13  
                                  digitalWrite(13, HIGH);
                                  delay(250);
                                  digitalWrite(13, LOW);
                                  delay(250);
                                  Serial.println("1 at position 1 of X - Tag saved at position1, 10 to 24 in EEPROM");
                               }
                           else
              
               //bitread position 2
                             if (bitRead(x,2) == 0)
                               {
                                //write 1       
                                  bitWrite(x, 2, 1);
                                 //write in eerpom
                                  for(byte b=0; b<bytesread; b++)
                                  { //addr2 = start in position 30
                                     EEPROM.write(addr2 + b, code[b]);
                                  }                     
                                //turn on led pin12  
                                  digitalWrite(12, HIGH);
                                  delay(250);
                                  digitalWrite(12, LOW);
                                  delay(250);
                                  Serial.println("1 at position 2 of X - Tag saved at position2, 30 to 44 in EEPROM");
                               }                 
                  }      
        }       
}

Thanks for any help

Here we go again. I have seen double posting and cross posting but they are usually caused by accident or ignorance, but not in your case it would seem

Anyway, where are the curly brackets for the else ?

      else

          //comparation2 value in eeprom with value read-tag
        for (byte b=2; b<13; b++)
        {
          if (EEPROM.read( b + offs2) != code [b])
          {

oh.. really thanks you have solved it for me :slight_smile: I hope will go fine with my next phase..

thanks so much