Arduino seemingly skipping a code line in a function?

Hi all,

Issue: for the function changeDetecRecorder, Arduino sometimes seemingly skips the line where a “timestamp” is intended to be recorded.

I’ve included my codes as well as the recorded TXT file (attached the main code and TXT for the sake of character limit).

Please let me know if I need to provide anything else, and thank you again.

Variables:

//pins:
int gLED = 2;
int IRLED = 13;
int waterSolenoid = 25;
int IRPin = 30;
int CLKPin = 6;
int DTPin = 7;
int touchPin = 9;
int buttonPin = 8;



int wsDuration = 105;
bool touchStateCurrent = 0;
bool touchStatePrior = 1;
int pulseNumber = 8;
int wsInactivePeriod = 250;
bool IRStateCurrent = 0;
bool IRStatePrior = 0;
int nosePokeDelay;
int waterDeliveryDelay = 250;
int i;
int rewardCounter; 
bool CLKCurrentState;
bool DTCurrentState;
bool CLKPreviousState;
int genericCounter = 0;
int DD = 01;
int MM = 01;
int YYYY = 2020;
int Hour = 01;
int Minutes = 01;
bool buttonState = 1;
int genericCounterCorrected;
int answerConfirmation = 1;
int interLickDelay = 100;
int ratIDNum = 1;
int ratWeight = 250;
String ratIDNumString = "";
String fileTitle = "";
String PString = "P";
String dotTXT = ".txt";
String underscore = "_";
String zeroString = "0";

bool 
gLEDStateCDR,
IRStateCDR,
touchStateCDR,
solenoidStateCDR,
rewardStateCDR;








//flags:
bool f1 = 0, f2 = 0, f3 = 0, f4 = 0, f5 = 6, f6 = 0, 
f7 = 0, f8 = 8, f9 = 0;

//time stamps:
unsigned long t1;
unsigned long t2;
unsigned long t3;
unsigned long t4;

V3.2.ino (37.8 KB)

P01_0104.TXT (866 Bytes)

i don’t know why it appears the value of millis() is not printing.

why are you repeatedly opening the file? why not statically initialize myFile to NULL and when you need to use it, check if it’s NULL, attempt to open it and check for error, and then use it. you should only need to open it once.

Thank you for your response.

If the file is open, and before the myFile.close () prompt someone accidentally unplugs the Arduino, would the data be lost? If not I will only open it once, like you mentioned.