I am having a bit of trouble loading values stored on an SD card and assigning them to variables within my program. I can achieve this as one big block of data, but would much prefer them to be saved to variables whilst in a loop or some other process.
My txt file has the following 6 ints & floats values, which are displayed vertically in the file:
2 0.003200 312 1 0.720000 8
Each of these values I want assigned to variables data1,....2,3,4,5,6. Unfortunately, the code I use below will never achieve this, but I am clueless as to any theory to solve this problem. Thanks in advance.
myFile = SD.open("test.txt", FILE_READ);
if (myFile) {
while (myFile.available()) {
data = myFile.read();
}
myFile.close();
}
else {
Serial.println("Read Error");
}
struct
could be a good choice, as you can then copy the contents of the struct as raw data to/from the card (though getting at it from another system like a PC would require knowledge of how the Arduino compiler packs structs). But you can also read the variables one by one; the big problem at present is that your code doesn't have any variables that it even attempts to load from the card. – Chris Stratton May 6 '18 at 21:22