How to delay with millis()/loop

edited June 2015 in Questions about Code

Hi there, I'm new to Processing and currently working on a project that uses the mic input. So, as you rise the volume, a certain message would show up on the display. Now I want the last message to show up a little longer (let's say for 10 sec), before the draw function loops again. Tried a boolean function, which either ends in noLoop (if true) or it switches right back to the first message (if right). Already googled a whole lot of different option, still did't find a good solution for my problem, yet. I'd really appreciate some help!

import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;
import ddf.minim.*;

int time = millis();
int timeLoop = 10000;

Minim minim;
AudioInput in;
float smoothingAlpha = 0.9;
float smoothMicrophoneValue = 0;
float microphoneLimit = 0.0367;
float microphoneThreshold = 0.0001;
PFont myFont;

//----------------------------------------------------------------

void setup(){
size(350, 500);
minim = new Minim(this); // Mikrofon
// use the getLineIn method of the Minim object to get an AudioInput
in = minim.getLineIn();
}

//----------------------------------------------------------------

void draw(){
frameRate(10);
background(#ED2D2D);

float microphoneValue = in.left.get(0);
microphoneValue = abs(microphoneValue);
microphoneValue = smoothMicrophoneValue = smoothingAlpha * smoothMicrophoneValue + (1-smoothingAlpha) *
microphoneValue;

//----------------------------------------------------------------

if(microphoneValue*18 <= 2){<br> myFont = createFont("Apercu-Bold", 32);
textFont(myFont);
textAlign(CENTER, CENTER);
text("say it to me", width/2, 225);
}

//----------------------------------------------------------------

if((microphoneValue*18 > 2)&&(microphoneValue*18 < 5)){
myFont = createFont("Apercu-Bold", 32);
textFont(myFont);
textAlign(CENTER, CENTER);
text("louder!", width/2, 225);
}

//----------------------------------------------------------------

if(microphoneValue*18 > 5){
time = 0;
println(millis());
boolean b = millis() < timeLoop;
if(b == true) {
println("noLoop " + millis());
noLoop();}
if(b==false){
println("loop " + millis());
loop();}
myFont = createFont("Apercu-Bold", 32);
textFont(myFont);
textAlign(CENTER, CENTER);
text("hell yeah!", width/2, 225);
}
}

Answers

Sign In or Register to comment.