Alright so nothing is working yet. I’m currently trying it on a simpler scale – using potentiometer and drawing lines. It’s similar anyway, so I thought I’d figure this thing out using potentiometer
I just have a question: Does the value for the array index reset to 0? From as far as I know (which is probably wrong
), the splitTokens() parses a string and puts it into array as
val [strIndex0]
where this is the first value from the serial.
Now, as the serial is being read, given that it has 2 values, does the index reset after \n?
On another note…I’m working on this and this is what I have
import processing.serial.*;
Serial port;
float[] coords = new float [2];
float x, y;
float px, py;
void setup(){
background(1);
port = new Serial (this, "COM12", 115200);
}
void serialEvent(final Serial port){
coords = float(splitTokens(port.readStringUntil('\n')));
}
void draw(){
if(port.available() > 0){
index = 0;
serialEvent(port);
x = coords[0];
y = coords[1];
line(px, py, x, y);
px = x;
py = y;
}
}
The Arduino:
void setup() {
Serial.begin(115200);
}
void loop() {
int x = analogRead(A1);
int y = analogRead(A0);
int x1 = map(x, 1023, 0, -10, 10);
int y1 = map(y, 0, 1023, -10, 10);
Serial.print(x1); Serial.write('\t');
Serial.print(y1); Serial.write('\t');
Serial.println('\n');
}
Is the arduino side correct? I wont want to be referring to tsv and newline and then it turns out I’m wrong 