Hey there,
I am wondering if there's a way to have two loops running in Processing with independent timing. Here are the specifics of my application:
- the program is continuously reading data from serial port (works fine)
- while data matches certain parameters, trigger a sound that repeats every few seconds
- for different values of incoming data, trigger sound at different rates. (I can do this with switch/case pretty easily).
I'm using the minim library. I have the trigger set up fine; it's getting the sound to repeat properly that isn't working. If I put in a delay(1000) then the whole program pauses for one second, which isn't acceptable. Is there a way that I can sort of have one function running on its own loop while the whole program keeps going?
Here's what I have now, pretty simple -- all the math and stuff leading up to getting datapoint works fine
Code:
// if datapoint is a larger number than (average of last samples plus 5% = 1.05 f) then trigger the sound
if ( datapoint > 1.05 * f) {
print("EDGE DETECT at ");
print(datapoint);
print(" : ");
println(f);
beep.trigger();
delay(1000);
}
this pauses the sketch for 1 second, obviously. I need to keep the rest of it running and just pause the audio loop bit.
I tried to make it a function by replacing the last two lines with playBeep(); and making this simple function
Code:
void playBeep() {
beep.trigger();
delay(1000);
}
That does the same thing.
So, any way I can keep this delay separate from the execution of the main sketch? I also can't write the delay into the sound file because of the nature of the trigger() function in minim.
Thanks all.
CUID