Reading from the EEPROM

When the values in the EEPROM were bytes, this function worked well, however now that the values saved in the EEPROM are int, the function doesnt work.
For example, the code saved in the EEPROM at address 0 is 12379, therefor accoding to the code below, serial print should display sucess if fileName is equal to the value at address 0.
Filename.toInt is the converstion from string to int.

for (int idx = 10000; idx < 32766; idx++)
{
EEPROM.read(idx);

if( fileName.toInt() == EEPROM.read(idx) )
{
Serial.println("Success");

myservox.write(180);
delay(20);
lcd.setCursor(0,0);
}
}

EEPROM.read returns a byte, hence your problem with int. Try EEPROM.get instead. You'll need to fix your loop to increment by two though.

Mighty big EEPROM you have there too.

Hi Bill thanks for your reply, I tried EEPROM.get but it doesnt work. You mention that I should increment by 2 in the loop, but then wouldnt that not read hald of the values in the EEPROM?

donyen:
For example, the code saved in the EEPROM at address 0 is 12379, therefor accoding to the code below, serial print should display sucess if fileName is equal to the value at address 0.

Your code doesn't address EEPROM location 0. The for loop with index 'idx' begins at 10000. Please explain.

An integer occupies more than one byte, probably two unless you have something with a 32 bit architecture. So you need to move the size of an int between reads.

As to your code not working please post it.

aarg:
Your code doesn't address EEPROM location 0. The for loop with index 'idx' begins at 10000. Please explain.

I thought that the loop reads the values not the address number. Basically in my EEPROM, the values are saved like this e.g.
addr 0 val 53235
addr 1 val 34445
addr 3 val 21524
now the idx begins at 10000 because it loops trhough the values not the addr.

wildbill:
An integer occupies more than one byte, probably two unless you have something with a 32 bit architecture. So you need to move the size of an int between reads.

As to your code not working please post it.

wildbill:
An integer occupies more than one byte, probably two unless you have something with a 32 bit architecture. So you need to move the size of an int between reads.

As to your code not working please post it.
[/quote

wildbill:
An integer occupies more than one byte, probably two unless you have something with a 32 bit architecture. So you need to move the size of an int between reads.

As to your code not working please post it.

Its a final project so Its really long code. I do believe that it is the EEPROM.read that is the problem as that reads bytes, so im focusing to find the solution to this problem.

So make a little sketch that illustrates the problem. Better to leave all the irrelevant stuff behind anyway.

wildbill:
EEPROM.read returns a byte, hence your problem with int. Try EEPROM.get instead. You'll need to fix your loop to increment by two though.

Mighty big EEPROM you have there too.

ooops ma bad you was right thanks a lot KARMA for youu

donyen:
Hi Bill thanks for your reply, I tried EEPROM.get but it doesnt work. You mention that I should increment by 2 in the loop, but then wouldnt that not read hald of the values in the EEPROM?

Ok so Ive done what you said and it does work sort of but I realised there is a problem, the problem is that it will only become success if the fileName is the last Number entered on the EEPROM, so lets say ...my serial monitor displays;
0 20000
1 34888
2 24442

it will only achieve success if fileName is the last saved value on the EEPROM, so (2 24442)... my code is below;

for (byte idx = 0; idx < 256; idx++)
{

EEPROM.get(idx, val);

if( fileName.toInt() == EEPROM.get(idx, val) && fileName.toInt() <=20000 )
{
Serial.println("Success");
counterA+=1;
myservox.write(180);
delay(20);
lcd.setCursor(0,0);
lcd.clear();
lcd.print("Thank You......................");
lcd.setCursor(0,1);
lcd.print("Goodbye A......................");
delay(5000);
myservox.write(0);
lcd.clear();
digitalWrite(laserPin3, HIGH);
Serial.print("Number of parking areas in Area A: ");
Serial.println(counterA);
loop();
break;

}
if( fileName.toInt() == EEPROM.get(idx,val) && fileName.toInt() >=25000 )
{
Serial.println("Success");
counterB+=1;
myservox.write(180);
delay(20);
lcd.setCursor(0,0);
lcd.clear();
lcd.print("Thank You......................");
lcd.setCursor(0,1);
lcd.print("Goodbye B......................");
delay(5000);
myservox.write(0);
lcd.clear();
digitalWrite(laserPin3, HIGH);
Serial.print("Number of parking areas in Area B: ");
Serial.println(counterB);
loop();
break;

}
else
{
loop();
}

}