Somthing to run, only when called

Hello

Is it possible to make somthing out of the void loop() ? etc. somthing like "void writeSd()", that can save data to a SD-card. If that is possible, how do i call the WriteSd() from the loop, ONLY one time??. I my mind it is not nessecary to read the whole loop, when the program has to write to the SD-card, ect. every 10 minutes. This will only cost on the performance.

Sorry for my bad english, but this is a fantastic help-site, for learning.

Is it possible to make somthing out of the void loop() ? etc. somthing like "void writeSd()", that can save data to a SD-card.

Yes, it is possible to develop, and call, functions.

If that is possible, how do i call the WriteSd() from the loop, ONLY one time??.

Use a global, boolean, variable, initially set to true. Test that variable in loop(). If it is true, call the function and set the variable to false.

bool needToLog = true;

void loop()
{
   if(needToLog)
   {
      writeSd();
      needToLog = false;
  }
}

Thanks PoulS

When I´m doing:

if (log1 = true) {   
      Serial.print(F("  "));
      Serial.print(WattSD);
      Serial.print(F("   "));
      char filename[] = "LOG_096.txt";
      if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
         if (!myFile.open(filename, O_RDWR | O_CREAT | O_AT_END)) {
              sd.errorHalt("SDFAILD");
              }
      log1 = false;
      WriteSd();
    }

I got the error that WriteSd(); isen´t declared in the scoop. How to do that??

if (log1 = true) {

==, not =, though the == true part is not required.

I got the error that WriteSd(); isen´t declared in the scoop. How to do that??

You need to create that function:

void WriteSd()
{
  // Probably want to do something
}

THANKS Poul!!!!

My bad was little vs. big letters (WriteSd was anthoer place been to writeSd).... Sorry my bad..!