joining 3 8*8 sensor readings in to 24*8

Im not sure if i am going about this the right way and thought I would see if anyone else has a better idea.

I have 3 Sensors set up beside each other. The sensors are an 8*8 thermopile array (kind of like a camera)

Instead of having 3 independent arrays I decided to look at combining them in to a 24*8 grid.

What i came up with seems to work but not sure if I am asking for trouble using nexted while statements like I have.

I would appreciate any sugestions on this.

void loop() {

int r=0, c=0, l=0, scount = 0;

Serial.print("[");
    while(r<=63){
      Serial.print(osi1.rawReading(r));
      Serial.print(", ");
      r++;
    if( r%8 == 0 ){
      while(c<=63){
        Serial.print(osi2.rawReading(c));
        Serial.print(", ");
        c++;
        scount++;
      if( c%8 == 0 ){
        while(l<=63){
          Serial.print(osi3.rawReading(l));
          Serial.print(", ");
          l++;
          scount++;
        if( l%8 == 0 ){
          Serial.println();
          break;
        }
      }
      break;
     }
    }
  }
  scount++;
}
Serial.println("]");
Serial.print("Pixel Count: ");
Serial.println(scount);

delay(1000);
}

If it works, ok, but it may be clearer if it looks like this (I think it is the same thing)

for (i=0 to 7) // for each row
{
 for (j = 0 to 7)  // each column of osi1
   process osi1[i*8 + j]
 for (j = 0 to 7)  // each column of osi2
   process osi2[i*8 + j]
for (j = 0 to 7)  // each column of osi3
  process osi3[i*8 + j]
}

I’m having a real problem understanding what order it prints the arrays in.

But I think the way I would have coded this Is much as Marco_c suggests…

for (int r = 0; r < 8; r++) {
  for (int c = 0; c < 8; c++) {
    Serial.print(osi1.rawReading(r*8+c));
    Serial.print(", ");
  }
  for (int c = 0; c < 8; c++) {
    Serial.print(osi2.rawReading(r*8+c));
    Serial.print(", ");
  }
  for (int c = 0; c < 8; c++) {
    Serial.print(osi3.rawReading(r*8+c));
    Serial.print(", ");
  }
  Serial.println();
}

Which I think is what you are trying to do. But like I said, very hard to untangle the while loops (especially given your unusual indenting style).

In fact you might even consider placing references to osi1…osi3 in an array, and then…

for (int r = 0; r < 8; r++) {
  for (int i = 0; i < 3; i++) {
    for (int c = 0; c < 8; c++) {
      Serial.print(osi[i].rawReading(r*8+c));
      Serial.print(", ");
    }
  }
  Serial.println();
}

As an aside, ‘l’ is usually considered a very poor choice of variable name. In some mono-space fonts it’s very difficult to tell the difference between the digit ‘1’ and a lower case letter ‘l’:

l1l1

Also in most sans-serif fonts the capital letter ‘I’ looks almost the same as lower case ‘l’ as well:
lIlI

Im just about to try out what @marco_c sugested and clean it up a bit. It does not need to be human readable as the output is going in to somethign else. Attached is a video.

There is sensor overlap on purpose so as to eliminate any blind spot but the orientation gives me a good 160 odd degrees of coverage.

Thanks for the input guys :slight_smile: cleaning it up like this will make life a little easier.

Helps if I attach the file.

3SensorTest.zip (54.6 KB)