Good day All,
My current project requires reading values from Ultrasonic sensors and writing them to a .txt file on a SD card. However upon first start up the an initial heading is printed in the .txt file in the setup() section. Now this is where I need help. Should the project be powered off and on again I don't want the heading to be written again. Is there a way to write an if statement to read from the .txt. file to prevent the heading from being written again to the SD card. I saw that strncmp can be used in such a case, but could not yet have figured it out. I was hoping someone could help me with an example of something similar. This is the code with strncmp that I tried but could not get working (Given the title was already printed to the .txt file):
myFile = SD.open("Diesel log.txt", FILE_WRITE);
while(myFile.available()){
myFile.read(buf[4]);
if(strncmp(&buf,"SGD",0)==0){
Serial.println("FOund line");
}else{
Serial.println("No line");
}
}
myFile.println("SGD BOERDERY DIESEL LOG");
myFile.print("DATE");
myFile.print("\t");
myFile.print("TIME LOGGED");
myFile.print("\t");
myFile.print("\t");
myFile.print("TANK 1:");
myFile.print("\t");
myFile.println("TANK 2:");
myFile.close();
Your help is much appreciated.