DataloggingExamples icon indicating copy to clipboard operation
DataloggingExamples copied to clipboard

SDCardDataLoggerWithRTC.ino Time Logic Error

Open kd8bxp opened this issue 10 years ago • 0 comments

1st thank you for the sketch, it saved me a lot of looking but I think I found a logic error, The way the sketch is written now, it will stop working if/when the seconds are equal or over 49 IF seconds go from zero to 59, in ten second steps then 49+10 would be 59, seconds will never be greater then 59. The sketch will hang, and never get pass this. A better way to do this is with millis() int currentmillis = 0;

void loop() { currentmillis = millis(); // if ten seconds have passed: if ((currentmillis - lastReadTime) > (interval * 1000)) { lastReadTime = currentmillis; ……. } }

So now I'm looking at time past in milliseconds and it shouldn't matter if the seconds is 49 or greater. currentmillis = 40000 (40 seconds) lastReadTime = 9000 interval = 30

if ((40000 - 9000) > (30 * 1000)) {do stuff} or if (31000 > 30000) {do stuff}

Thanks again.

kd8bxp avatar Apr 29 '15 23:04 kd8bxp