 # Assistance needed: Converting a 1D array to a 2D array

Hello,

I am new to programming and would appreciate your help to solve and understand the following problem:

1. Existing 1D array → temperatures* This array has 64 elements, of data type float, created in an Arduino sketch. I have verified that this sketch is function properly in a sketch that reads the temperatures sensed by a 4 x 16 array IR sensor. E.g. I can watch the temperatures of elements in the 4 x 16 array change using the Arduino’s serial monitor.*
2. I need assistance to do the following:
In the Arduino sketch that creates temperatures_, I need to convert the 1D temperatures array to a 4 x 16 element 2D array. The 2D array is used by a Processing sketch that draws a 4 x 16 matrix on the PC monitor.
3. As a test, the Arduino sketch below successfully does the following: It creates the fixed element values of 0 through 63, communicates these values via the serial interface to the Processing sketch, which are then used by the Processing sketch to display them as a 4 x 16 matrix on the PC’s monitor._

My question: How do I modify the sketch below to cause the Processing sketch to draw the elements of temperatures as a 4 x 16 matrix on the PC’s monitor?[/b]
Thanks, Bob
```
*//Prints an array string of temperatures formatted for use as input to Processing: Collecting_and_storing_information_Learning_2_4x16_Processing_4
//Each element is separated with a ‘\t’, each line is separated with a ‘\n’, and the array ends with ‘!’
// ‘\t’, ‘\n’ and ‘!’ are required by the Processing sketch.

//define the size of array
#define ARRAYi 4 // i
#define ARRAYj 16 // j
//create the array
int sensorArray [ARRAYi][ARRAYj];
int i,j,x;

void ProcessingPrintTemperatures_1() {

if (x>63)
{
x=0;
}
for (i=0;i<ARRAYi;i++)
{
for (j=0;j<ARRAYj;j++)
{
sensorArray[i][j]=x;
x++;
}
}
sendArray();
delay(500);
}

void sendArray ()
{
for (i=0;i<ARRAYi;i++)
{
for (j=0;j<ARRAYj;j++)
{
Serial.print(sensorArray[i][j]);
Serial.print(’\t’); //tab character
}
Serial.print(’\n’); //new line c
}
Serial.print(’!’);
}

//--------------------------
__```*__

please use CTRL-T before posting code, that does auto formatting /indent that makes code more readable

thank you

you must add two counters in processing, one that counts up to 16 and then reset to zero and increments the second counter.

``````x = 0;
y = 0;
for (int i=0; i<64; i++)  // temps coming in
{
drawsensor(x, y, sensor[i]);  // position value
x++;
if (x == 16)
{
x = 0;
y++;
}
}
``````