I've tried to add "else" to the code as your suggestion below. It didn't help
if (! photoFile)
{
Serial.println(F("couldn't create file or SD card full"));
return;
else{
Serial.println(F("File created."));
Serial.print(F("Logging to: "));
Serial.println(filename);
delay (1000);
}
}
I also tried to change code as suggested below. It didn't help either
char filename[] = "C329Ph00.jpg";
static byte i = 0;
if (i <= 10)
{
filename[6] = i / 10 + '0';
filename[7] = i % 10 + '0';
Serial.println(filename);
delay(1000);
i++;
}
}
if (! photoFile)
{
Serial.println(F("couldn't create file or SD card full"));
return;
else{
Serial.println(F("File created."));
Serial.print(F("Logging to: "));
Serial.println(filename);
delay (1000);
}
}
The thing is, if I removed the rest of the codes from "void Removefile()". The camera will take 10 snapshots as I expected. But if I add the "void Removefile()" back. It will take only 1 snapshot.
if (! photoFile)
{
Serial.println(F("couldn't create file or SD card full"));
return;
else{
Serial.println(F("File created."));
Serial.print(F("Logging to: "));
Serial.println(filename);
delay (1000);
}
}
First of all the if & else should be pairs
If (condition) {
// do this
}
else {
// do that
}
Second and more importantly, the return; in loop() causes loop to start over, so if the the photofile was not created, nothing after that gets executed and loop() starts over. (afterwhich )
Thirdly and most important,, if you don't understand, don't start guessing for an answer.. i know these guys on this forum tend to give you only half of one, but don't buy into it. Go through you code, write comments behind all the lines that test for your exceptions and check your main counter and execution. if the file cannot be created what do i want the program to do and if it is created what to i want it to do etc.
did that snippet even compile ?
you don't understand, don't start guessing for an answer.. i know these guys on this forum tend to give you only half of one, but don't buy into it. Go through you code, write comments behind all the lines that test for your exceptions and check your main counter and execution.
Good advice.
If you don't understand what your own code does - every line - then there's little the experts can do to help - other than pointing at the likely issues - so you can do your own research.
If they give complete answers - you won't learn anythnig, and they waste their time!
Thanks for the advice. My codes work fine, but just not working as my expectation. it might miss something unexpected that I didn't see. I just want some experts can point out what has happened.
Thank you for your contributions and suggestions. The serial monitor does not allow me to copy; Otherwise, I will copy the whole serial monitor output to show and easy to explain.
I will ask some software engineerings within my company if they can find something wrong with the codes. I will come back to tell you what was wrong. Cheers!