Hello.
This can be considered an extension of my previous thread here Using two different readStringUntil "characters"
Now, I am working on a basic Arduino project, but for understand Processing, I am now using a potentiometer to extend a line across the screen. I wish to extend it to 2D because it has been 1D
Through Serial, I receive the values of the pot via Arduino. I know that separating a string using splitTokens() will give a pre-initialized array at some index that string.
However here is my code, and for some reason, it gives me an error about the array being null
For the sake of trying to figure this thing out I didn’t add the line movement yet. For now I want to know what in the world is happening
import processing.serial.*;
Serial port;
String[] input = {};
float val;
void setup(){
stroke(250);
size(1000, 700);
port = new Serial (this, "COM12", 115200);
port.bufferUntil('\n');
}
void serialEvent(Serial port){
// input = float((port.readStringUntil('\n'));
input = splitTokens(port.readString());
}
void draw(){
background(1);
println(input[0]);
}
The line println(input[0]);
will give me the error, however removing the [] part gives me the raw values, just as I am reading them from Arduino serial. println(input);
works
But I want to interact with the individual values.
Please help. I have a deadline to meet on the 10th and I’m still on the processing basics.
Thanks