How to waste time in Processing? (delay with Arduino)

hello, how to wait time in processing?
and im haven’t arduino to use delay() in serial.
so, can you help me?

You can make a timer using millis()

draw () runs on and on but the next step is only done
when if(millis()-timer > 5000) {

and say int timer = millis(); to start the timer

1 Like

what? no, just wait per frame, not per frame’s
no, im sure can do that with milis(), but this is tons of code, is not mine (no offense)

1 Like

In theory, you can use the same timer in a while loop
and stay in draw() (in the same frame)

1 Like

You do not want a (long) delay inside the draw method otherwise it will inhibit event handling and make the app unresponsive.

Why do you want a delay? Do you actually need a delay?

It would help if you explain more about what you attempting to do in your sketch.

2 Likes

working with Arduino you sometimes need a delay iirc.

But I would not recommend to use more than 200 millis…

1 Like

You can try using the pause function in this sketch

void setup() {
  size(400, 300);
  textSize(30);
}

void draw() {
  background(20);
  fill(255);
  // Display time since sketch started
  text(millis(), 50, 100);
}

// Pause time in milliseconds
void pause(int time_ms) {
  try {
    Thread.sleep(time_ms);
  }
  catch(Exception e) {
    println(e.toString());
  }
}

void keyTyped() {
  if (key == 'p')
    pause(2000);  // Pause for 2 seconds
}
1 Like

yes, im try pause(), but i have an version 4.3 don’t sure that will be work

The sketch worked for me in 4.3 :grin:

2 Likes

ok, thanx quark (this coment for this this line for just here’s be >20 simvols)