I know about Serial.println(). But because i just want to read integer values, it seems Serial.write() should suffice. But the problem is whenever i try to read from serial port and turn my potentiometer that is connected to my arduino board, the change in value gets picked up very late. I think i understand why that happens. But i just need to know how to sync up supercollider with how fast new data arrives in the serial buffer, i think? This is my arduino code.
void setup() {
Serial.begin(9600);
}
void loop() {
//only sending one byte per 10 millisecond
byte val = map(analogRead(A0), 0, 1023, 0, 255);
int bytesAvailable = Serial.availableForWrite(); //checking if there is space on the buffer
if(bytesAvailable > 0){
Serial.write(val);
}
delay(10);
}
Here is my supercollider code
(
p = SerialPort(
"COM4",
baudrate: 9600)
)
(
fork {
loop {
p.read.postln;
0.01.wait;
}
}
)
SerialPort.closeAll;
So i assume every 10 milliseconds the arduino puts a new byte onto the serial buffer. And i also assum that p.read reads the next byte in the buffer, also every 10 milliseconds. But still when i turn the potentiometer it responds super late.
So my question is, how do i sync up my arduino and supercollider to get the best responsiveness? Maybe i should use something else than serial? I basically just want my knob to change parameter values in supercollider, so that i can control supercollider as a synth for playing live.