[SOLVED] Making a void section run only once

Hi. I will try and attach the code below but is quite large and you probably won't need to rear it to know what I mean.

Is there a way of making a void section only run once?

On part of my code I basically call the current Hour, Minute and Second and if it matches a set time, the 'void lunarfade' will run. However, as expected it will call the void multiple times in that one second and I can only have it to run once.

Anyone have any ideas how to do this? I'm guessing its pretty simple but can't figure it out.

Thanks,
Steve

Is there a way of making a void section only run once

If you mean "is there a way to call a function only once?", yes, just put the function call at the end of the setup() function.

Otherwise, only call the function when the condition changes not whilst the condition is true.

pseudo code:

bool flag = false;

loop()
{
  if( time == set_time )
  {
    if( flag == false )
    {
      lunarfade();
      flag = true;
    }
  }
  else
    flag = false;
}

what tammy said, but you don't need the else clause.

On the contrary, you do need the else.

Or at least you do if you intend lunarfade() to execute each time that 'time' is equal for the first time to set_time each day :stuck_out_tongue:

tammytam:
pseudo code:

bool flag = false;

loop()
{
  if( time == set_time )
  {
    if( flag == false )
    {
      lunarfade();
      flag = true;
    }
  }
  else
    flag = false;
}

Thanks Tammytam. I have now built something similar into it. Than you. :slight_smile: