Im getting a two second delay when reading the serial port on the Arduino from Processing…
My arduino code looks like:
void loop() {
// wait if any serial is going on
FreqCounter::f_comp=106;
FreqCounter::start(1000);
while (FreqCounter::f_ready == 0)
frq=FreqCounter::f_freq;
Serial.println(frq);
}
My Processing code looks like:
while(true) {
inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int
frequency = int(inString);
println(frequency);
if(frequency >= 0 && frequency < 3000) {
sine.setFreq(frequency);
}
// sine.setFreq(5000);
}
}
Basically the Arduino calculates a frequency based on the position of my finger acting as a potentiometer and sends the frequency to Processing. Processing takes that frequency and turns it into sound.
But I get a 2 second delay between touching and hearing sound…
Any ideas why this is happening?
Thanks!