Well, println(vals);
logs the whole content of the array val[].
While println(vals[0]);
logs only the value stored at index 0
.
The []
is called the array access operator btW:
You can learn more about Java arrays here:
The sketch Iāve posted in this thread is about 90% the same from my posted link:
Basically, Iāve simply replaced:
static final int PORT_INDEX = 0, BAUDS = 9600;
int[] vals = {};
new Serial(this, ports[PORT_INDEX], BAUDS).bufferUntil(ENTER);
w/
static final int VALS = 2;
int[] vals = new int[VALS];
new Serial(this, "COM12", 115200).bufferUntil(ENTER);
BtW, the constant PORT_INDEX has to match an index value from the array returned by Serial.list() which corresponds to the port thatās gonna receive bytes from the Arduino:
In your computer, that seems āCOM12ā matches the 1 connected to your Arduino.
However, if you simply copy & paste it on some other computer, chances are āCOM12ā might fail!
Also, even if in the same computer, but w/ a diff. OS, like some Linux distro, āCOM12ā wonāt work at all; b/c Linux uses a completely diff. string for ports!
Also, if you happen to send a TSV row w/ more data than just 2, int[] vals = new int[2];
isnāt enough, obviously!
Therefore, when dealing w/ any Arduino code, we should consider such code a template.
B/c each computer and OS will have its own port number!
Thus we have to slightly customize such code to the values used by own particular computer configuration rather than directly use an unmodified copy & paste serial program!