how to put a timer?

void setup() {
  size(400, 400);
  textSize(64);
  textAlign(CENTER, CENTER);
  fill(255);
}

void draw() {
  background(90);
  object();
}

void object () {
  if (blink(30)) {
    text("LED", width/2, height/2);
  }
}
boolean blink(int span) {
  return frameCount%(span*2) < span;
}
Tagged:

Answers

  • Basically I want to put a timer that stops the "blinking" effect after a few seconds

  • edited March 2018 Answer ✓

    One variable int startTime is defined before setup() and set at the end of setup() to millis()

    in draw say in line 10

    if(millis() < startTime+3*1000)  // 3 seconds
        object();
    

    Which would deliver true for 3 seconds

  • @Chrisir Thanks man, its exactly what I need.

Sign In or Register to comment.