Hi all,
I am working on a data logger that writes to an SD-card.
Before starting the logging, the program should verify if the file already exists. If so, it should ask me whether to erase it or not and wait for that keypress.
What would be the best way to implement this? I have worked out a solution, but it seems kludgier than needed (and checks if the file exists a second time and then erasing it when Y is pressed).
Thank you very much for any hints.
//check if file exists, ask whether to overwrite or exit function
if (SD.exists(filename)){
lcd.clear();
lcd.setCursor(4,0);
lcd.print("File exists.");
lcd.setCursor(5,1);
lcd.print("Overwrite?");
lcd.setCursor(0,2);
lcd.print("Y:Return / N:Escape");
while(digitalRead(NO_BUTTON_PIN)==HIGH && digitalRead(YES_BUTTON_PIN)==HIGH){
delay(100);
}
if(digitalRead(NO_BUTTON_PIN)==LOW){
Serial.println("Escape, exit");
return;
}
Serial.println("Continue, overwrite file");
lcd.clear();
lcd.setCursor(2,0);
lcd.print("Deleting File");
delay(2000);
}
//as it needs to pass above code to come here, verify again if file exists and delete
if (SD.exists(filename)){
SD.remove(filename);
}
//..... datalogging routine......