Hello,
I am new to programming and would appreciate your help to solve and understand the following problem:
1. Existing 1D array ->
temperatures[i] 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], I need to convert the 1D temperatures[i] 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[i] as a 4 x 16 matrix on the PC's monitor?
- //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('!');
- }
- //--------------------------
Thanks for your help,
Bob
1