Call function after a period || Save date and time on SD card

Hi , i have two function and i call them in loop, but i want to call one function on intervals of time,for example every 10 minutes, but i dont want to stop the second function from calling. Can someone give me some info abount how i do it ? Thanks

Use millis() and store the times when things last happened (in a global variable of unsigned long type).

See blink without delay example, or the many threads/tutorials/guides on doing multiple things at once. This is a very frequently asked question, and there is a huge volume of information on it.

Thanks :smiley:

Example :

unsigned long previousMillis = 0;
const long interval = 30000;

void setup()
{
...
}

void loop()
{
unsigned long currentMillis = millis();

    if (currentMillis - previousMillis >= interval) 
   {
      previousMillis = currentMillis;
      Serial.println("TEST");
    }
}

Hello again. I have a SD arduino module and i want to save in a file the date and hour. I tried in this mode :

File dataFile = SD.open("DATALOG.txt", FILE_WRITE);
      if (dataFile) {

        unsigned long age, date, time;
        int year;
        byte month, day, hour, minute, second, hundredths;
        gps.get_datetime(&date, &time, &age);
        gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);

        dataFile.print(printf("%02d:%02d --- %02d / %02d / %04d", hour, minute, day, month, year));
        dataFile.print(",");
        dataFile.print(flat, 7);
        dataFile.print(",");
        dataFile.print(flon, 7);
        dataFile.print(",");
        dataFile.print(gps.f_speed_kmph());
        dataFile.print(",");
        dataFile.println(gps.f_altitude());
        dataFile.close();
}

But doesnt work.

This is the document content :

-1,47.6601257,23.5503559,1.37,177.80
-1,47.6601524,23.5503482,2.67,172.00
-1,47.6601638,23.5503311,2.00,169.10
-1,47.6601676,23.5503158,2.07,168.80
-1,47.6601715,23.5503025,2.72,168.90
-1,47.6601867,23.5503082,2.46,166.10
-1,47.6601905,23.5503082,1.81,166.30
-1,47.6601676,23.5502834,1.43,168.50
-1,47.6601371,23.5502643,1.65,171.90

The data received for this line : dataFile.print(printf("%02d:%02d --- %02d / %02d / %04d", hour, minute, day, month, year)); is "-1"

This is the solution :

Just replace this line : 
dataFile.print(printf("%02d:%02d --- %02d / %02d / %04d", hour, minute, day, month, year));

With this:
        dataFile.print(day);
        dataFile.print("/");
        dataFile.print(month);
        dataFile.print("/");
        dataFile.print(year);
        dataFile.print(" --- ");
        dataFile.print(hour);
        dataFile.print(":");
        dataFile.print(minute);

But now i want to know how i can change time zone ?

redaot:
But now i want to know how i can change time zone ?

Just add or subtract from hours as needed.

Delta_G:
Just add or subtract from hours as needed.

I think about this, but when you do this : hour = hour+3; if the clock is 22:14 it will be 25:15...

hour = (hour +3)%24
void setup() {
  Serial.begin(9600);
  for ( byte i = 0; i < 25; i++)
  { 
    byte hr = i + 3;
    Serial.println(hr % 24);
  }
}
void loop() {}

cattledog:

hour = (hour +3)%24

Keep in mind, this doesn't change the date.

Hi :smiley: Can someone tell me what is this : GPS_INVALID_F_ANGLE ?

I use it in if : if (flat == TinyGPS::GPS_INVALID_F_ANGLE )

Thanks

Can someone tell me what is this : GPS_INVALID_F_ANGLE ?

It is a value defined in the TinyGPS library. You can find the library in the folder with your sketches, and there will be two files TinyGPS.cpp and TinyGPS.h. Open the files with a text editor and look around. This is what I found at line 427 of TinyGPS.cpp

const float TinyGPS::GPS_INVALID_F_ANGLE = 1000.0;

So your line in question actually resolves to

if (flat == 1000.0)

I think the value is used as an error message.