Leaving elapsedMillis running

This is probably a quickie - while writing some code I realized that in one of my calls to elapsedmillis, it might be the case that it gets called once and doesn’t get reset for extended periods of time. ie:

(some very pseudo code)
elapsedMillis myTimer;
int thisTimer = 2000;
bool thing = false;

if(thing == false)
myTimer = 0;
thing = true;

obviously that logic is crap but my timer starts running and for whatever reason, ‘thing’ never gets set to false again so the timer just keeps running. Am I eating up resources leaving it running like that and/or is there a ‘stop’? I don’t see something obvious in elapsedMillis.h (as installed by the particle visual studio library) that would allow one to stop the timer aside from some blocking logic (which defeats the purpose)

Just curious if thats a thing/if I should care about it or if just using millis() would be better in that case? (I’m betting it doesn’t matter or there probably would be a ‘stop’ function, but figured it was worth an ask)

ellapsedMillis is not running a timer but rather uses the system’s millis() counter to calculate the difference between the current count and the count at starting time.

Hence you cannot stop the counter as it is part of the device OS.

But when you are not calling any functions of the elapsedMillis object you won’t use extra clock cycles for it either.

1 Like

Thanks! Thats what I wanted to know :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.