I'm trying to read a pair of comma separated values, store the values into arrays, read the next pair of values, and append them to the arrays.
Right now I can store the first pair of values into the array. But when I try to increment the array index and use it for the next set, it does not increment and instead overwrites the first set.
My code right now looks like this:
void setup() {
// initialize serial:
Serial.begin(9600);
Serial.println("Ready");
}
void loop() {
int index = 0;
int t[50];
int n[50];
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
int c1 = Serial.parseInt();
// do it again:
int c2 = Serial.parseInt();
// look for newline
if (Serial.read() == '\n') {
Serial.println(c1, DEC);
Serial.println(c2, DEC);
t[index] = c1;
n[index] = c2;
++index;
}
//print what's currently in the arrays
Serial.println("Sequence");
int i;
for (i = 0; i < 10; i = i + 1) {
Serial.println(t[i]);
Serial.println(n[i]);
}
}
}