How to trigger function every "x" minutes?

Looking at the following code, how can I force the ‘snap’ routine to execute every 14 minutes?

#define PIN_STATUS 13
#define PIN_IR_LED 12
#define FREQ 38400  // IR frequence
//shutter sequence (on,off,on,off ... in microsecond)
unsigned long sequence[] = {2000,27830,390,1580,410,3580,400,63200,2000,27830,390,1580,410,3580,400,0};
int seq_l;
int lightningVal;

//oscd is a delay in microsecond used at each oscillation.
int oscd;
void oscillate(int pin, unsigned long n, int shine){
    int ir_status=0;
        ir_status  =  !ir_status; 
        digitalWrite(pin,  ir_status && shine);  
void snap(){
    int i;
    digitalWrite(PIN_STATUS,  1);  
        oscillate(PIN_IR_LED, sequence[i], i%2==0);
    digitalWrite(PIN_STATUS,  0);
void setup() {
    lightningVal = analogRead(LIGHTNING_TRIGGER_ANALOG_PIN);
        int min=1, max=100, i;
    int last_oscd=0;
    unsigned long before, intervalle;
    seq_l = sizeof(sequence)/sizeof(unsigned long);
    pinMode(PIN_STATUS, OUTPUT);
    pinMode(PIN_IR_LED, OUTPUT);
    //this "while" will process the best "oscd"
        oscillate(PIN_STATUS, FREQ, 1);
        if(intervalle >= 1000) max=oscd;
        else min=oscd;
        Serial.print(" : ");
    Serial.print("oscd: ");
    //rewrite the sequence array, we replace all values in microsecond by the number of oscillation
        sequence[i] = (sequence[i] * FREQ) / (intervalle * 1000);
void loop() {    
  int cmd;
  int newLightningVal = analogRead(LIGHTNING_TRIGGER_ANALOG_PIN);
  Serial.println(lightningVal, DEC);
  if (abs(newLightningVal - lightningVal) > TRIGGER_THRESHHOLD)
    Serial.println("Shutter triggered");

  lightningVal = newLightningVal;


Thanks for any and all help…


The millis() function returns the time since the Arduino was reset, in milliseconds. You can use the current time (as returned by millis()) and the time that the last call to snap() was made (as returned by millis()) to see is 14 minutes has elapsed, on each pass through loop(). If is has, call snap() and reset the time that snap() was last called.

The Mstimer2 library makes this a very simple task:


Thanks, Paul, and Lefty. Wasn't aware of the MsTimer2 like a champ....