// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
and this is my code, based on the example
myFile = SD.open("calibration.txt", FILE_WRITE);
if (myFile) {
for (i = 0; i <= 7; i++) {
myFile.print(analogRead(lineSensor[i]));
myFile.println("/");
}
myFile.close();
Serial.println("Data written");
} else {
// if the file didn't open, print an error:
Serial.println("error opening calibration.txt");
}
I always get "error opening calibration.txt", and I got no error messages while compiling.
ie, you get 49 so subtract 48 and you have converted it to a 1
However, I suspect that there may be a deeper problem. You saved 121 and you get back 1 then 2 then 1 using the "subtract 48" method but I suspect that you really want 121 in a variable. Is that right ?
h_anton:
I.e. I want 121 in array[0]; 66 in array[1]; ...
OK
Set an array index variable to zero
Set a target int variable to zero
Read a character.
If it is between '0' and '9' subtract 48 (or '0') to get the actual digit
Multiply the target variable by 10 and add the new digit to the result
Keep going until you get a '/' and the number will be in the target variable
Put it in the array and increment the array index variable
Keep going to the end of the file
Try this with pencil and paper to see how and why it works
Note that the target array must have been previously declared with enough elements to hold all of the numbers.