Better way to code 1 time executed statements

i'm using the following section of code in a timer:

if (SetLastNumber == false) // if false Lastnumber = EEPROM Value
        {
          SetLastNumber = true;
          //Last Number = EEPROM Value
        }
    else //Else LastNumber= 0
    {
      //Last Number=0
    }
   if (ReadActivationStartTime == false) //set millis starttime. read every time timer activates set to false at timer end to enable millis starttime set once per iteration
        {
          ReadActivationStartTime = true;
          StartTime = millis();
        }

//do rest of timer code

So What i have done is use booleans to read EEPROM value once and after the first count period it is true and as such Last number will be 0. And then i have used boolians again for the start time to ensure that it to would only be read once per iteration.

My problem is that it is messy and i think to complicated. is there a better way that someone can suggest to use so that eeprom value is used once to measure the elapsed time then is set to 0, and or a better way to have the start time of my timer read only once?

I removed alot of the code to make seeing my problem easier and left comments instead to see what each part does individually.

thanks for the suggestions in advance.

It’s always recommended you show us all the code.

i know thats the preference but i always prefer suggestions on other alternatives than people helping me by doing it. Just find i get more suggestions with an overview of my code than i do when i post completed code.

or a minimum example we can compile.


if you want to do something once, and it's at the start of the code, put it in the setup() and not in the loop()

1 Like

which is better improving the code or improving the architecture?

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