OK... LIKE I SAID... Its a mess. What was written at 4.34am isn't going to make sense. Sorry if I don't write perfectly pretty code all the time :![]()
This is where I am now... and it works well so far.
Its sending each line to the EEPROM if an SD card is present. Then I can easily read it back.
I have had to add a hash to the end of each line to allow it to find the end of the sentence. If there any way of getting it to ignore the spaces at the end of a row of text? I am assuming it jumps to the next line when it sees more than one space?
It would be nice if it simply read the entire row of 30 characters, spaces included. Then I could do away with the hash at the end.
void setup()
{
Serial.begin(9600); // Open serial communications and wait for port to open:
while (!Serial) {
}
Serial.print(F("Checking for SD card... "));
if (!SD.begin(4)) {
Serial.println(F("No SD card present, using memory stored data"));
return;
}
Serial.println(F("Found SD card"));
delay(80);
// Open the file for reading:
myFile = SD.open("SiteData.txt");
if (myFile) {
Serial.println(F("SiteData.txt:"));
Serial.println(F(" "));
// read from the file until there's nothing else in it:
while (myFile.available()) {
hash1=myFile.read(); //Search for a hash
if (hash1==35) { //If a hash is found, get the line number of the data
Serial.print(char(hash1)); //Display the hash+line number
data1=(myFile.read()-48);
data2=(myFile.read()-48);
data3=((data1*10)+data2); //Calculate which line number we are reading
Serial.print(data3);
EEPROM.write((data3*30)-30,data3); //Store the line number at its own line number address *30 then -30 (because there is no zero line number)
for (i=0;i<=12;i++) { //Skip the next 12 spaces/letters as they are the reference text. Just print them to the serial monitor
Serial.print(char(myFile.read()));
}
for (i=0;i<=30;i++) { //Read the next 30 letters or numbers and store them incrementally from the known line number start point
data1=(myFile.read());
if (data1==35) {break;} //If it finds another hash, then exit
Serial.print(char(data1));
EEPROM.write(((data3*30)-30)+i,data1);
}
Serial.print('\n'); //New line
}
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println(F("error opening SiteData.txt"));
}