# How to repeat 5 sec?

**URL:** <https://discourse.processing.org/t/how-to-repeat-5-sec/22113>\
**Category:** Coding Questions\
**Created:** [June 23, 2020, 8:04pm UTC](https://discourse.processing.org/t/how-to-repeat-5-sec/22113 "2020-06-23T20:04:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lee1](https://avatars.discourse-cdn.com/v4/letter/l/f9ae1b/32.png) [@lee1](https://discourse.processing.org/u/lee1)\
**Post date:** [June 23, 2020, 8:04pm UTC](https://discourse.processing.org/t/how-to-repeat-5-sec/22113/1 "2020-06-23T20:04:04Z")

</div>

how can repeat every code 5 sec forver?  
i try to find about that,  
i cant find “repeat using time”

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 23, 2020, 9:47pm UTC](https://discourse.processing.org/t/how-to-repeat-5-sec/22113/2 "2020-06-23T21:47:57Z")

</div>

here draw() runs on and on

- but i is incremented only once every 3 seconds

```auto
int timer; 
int i;
String textSlash="/"; 

void setup() {
  size(600, 600);
  timer = millis();
  background(0);
}

void draw() {
  background(0); 

  text("3 seconds have passed "+i, 44, 44);

  // This gets executed every 3 secs - while draw() keeps on running 60 times per second 
  if (millis() - timer > 3000) {
    timer = millis(); // reset timer for next round 
    i++; // increase i once every 3 secs
  }

  // do something else to show that draw() runs fast
  if (frameCount%9==0)
    if (textSlash.equals("\\")) {
      textSlash="/";
    } else {
      textSlash="\\";
    } 

  text(textSlash, 111, 111);
}

```
