hi,
i’m doing a project with Arduino DUE and i got a problem.
when i’m trying to read the variable from a txt file in the sd card, i dont get the right variable.
i tried to substract the ‘0’ in ASCII but its no use.
the odd thing is that I have 3 text file that read in my function, IR00, IR01 and IR02
the result that I get from the first two is incorrect and the result from the last one is right.
in the IR00 there are a value of 2, in the IR01 there are a value of 12 and in the IR02 there are a value of 2704.
here is the function that I’m using to get the value from the text files.
for example:
in sd card i have a file name IR00.txt, in it i have the number 2.
this is the part of the program that handles the IR00 part.
void RestoreCodetoMem(){
Serial.flush();
File IR01 = SD.open(“IR01.txt”);
if (IR01)
{
Serial.println(“Reading IR01 File”);
float decade = pow(10, (IR01.available() - 1));
while(IR01.available())
{
float temp = (IR01.read() - ‘0’);
codestorage[0][1] = temp*decade+codestorage[0][1];
decade = decade/10;
}
Serial.print("Code Lengh codestorage[0][1] = ");
Serial.println(codestorage[0][1]);
}
else
{
Serial.println(“Could not read IR01 file.”);
return;
}
IR01.close();
Serial.flush();
File IR02 = SD.open(“IR02.txt”);
if (IR02)
{
Serial.println(“Reading IR02 File”);
float decade = pow(10, (IR02.available() - 1));
while(IR02.available())
{
float temp = (IR02.read() - ‘0’);
codestorage[0][2] = temp*decade+codestorage[0][2];
decade = decade/10;
}
Serial.print("Code codestorage[0][2] = ");
Serial.println(codestorage[0][2]);
}
else
{
Serial.println(“Could not read IR02 file.”);
return;
}
IR02.close();
Serial.flush();
File IR03 = SD.open(“IR03.txt”);
if (IR03)
{
Serial.println(“Reading IR03 File”);
float decade = pow(10, (IR03.available() - 1));
while(IR03.available())
{
float temp = (IR03.read() - ‘0’);
codestorage[0][0] = temp*decade+codestorage[0][0];
decade = decade/10;
}
Serial.print("Code Type codestorage[0][0] = ");
Serial.println(codestorage[0][0]);
}
else
{
Serial.println(“Could not read IR00 file.”);
return;
}
IR03.close();
}
this function is called in the setup and put the value in my global array codestorage
i dont see what is the difference between the text file .
if I just read the value from the text file by using the Serial.wrtite() function I got the right value but when i want put them to the array something goes wrong.
what can i do to take/use and not just read the data from the sd card ?
please help !!!
note: codestorage = {0}; is a global array in the main program .