Maybe I'm just making things more complicated than they ought to be...
// number of values to read
const int NUM_VALUES = 5;
// array to store values
int values[NUM_VALUES];
// where to put the next raead value
int currIndex = 0;
// instead of multiple variables, name the array indexes
const int xIdx = 0;
const int yIdx = 1;
const int rIdx = 2;
const int gIdx = 3;
const int bIdx = 4;
// dump array contents on serial port
void printValues(const int ary[], int numElements) {
for (int i = 0; i < numElements; i++) {
Serial.println(ary[i], DEC);
}
}
void setup(){
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop() {
// do we have at least 1 byte in the serial buffer ?
if (Serial.available() > 0) {
// yes, read it
int value = Serial.read();
// store it into the array
values[currIndex] = value;
// next byte position into the array
currIndex++;
// have we filled the array ?
if (currIndex >= NUM_VALUES) {
// yes, dump its contents on the serial line
printValues(values, NUM_VALUES);
}
// start over
currIndex = 0;
}
}