Execute a method after X ammount of seconds outside draw() using millis

edited November 2014 in Questions about Code

I am tryin to execute a method after X ammount of seconds (Sort of pausing the program before actually calling the method to run. I am doing this outside draw() therefore it doesn't run constantly. I want the program to wait 5 seconds and then call the function.

This is the way I am trying to implement it:

int savedTime;
int totalTime = 5000;

void objectprocess(){
int passedTime = millis() - savedTime;

       if (passedTime > totalTime){
         changeImg(); 
     }
}

For some reason the method changeImg() is never called. Probably I need to fix something in the way the timer for the pause is working.

Many thanks for your time and help guys !

Answers

Sign In or Register to comment.