Initializing multiple timers within the draw loop ()

millis() is just counting the millis() since start of the Sketch

but you can use different length you wait before something happens



int xPos = 0;
int timer1 ;
int timer2 ;

void setup() { 
  size(400, 400);
  noStroke();
} 

void draw() { 
  background(220);

  if (millis() - timer1 > 3000) {
    // console.log(timer1);
    fill(255, 200, 40);
    rect(xPos, 30, 40, 40);
  }

  xPos = xPos + 1;

  if (millis() - timer1 > 5000) {
    timer2 = int(millis()/1000);
    //console.log("the new timer");
    //console.log(timer2);
    fill(0, 255, 0);
    rect(100, 100, 200, 200);
  }//if
}
//