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
}