noob question about two dimensional arrays

Hey all.

imagine having two different signals going into an arduino, these signals are both analog. based on both these signals an array is created.

12 arbitrary values of signal one and two is chosen and these are placed along the X- and Y- axis of the array respectively. Whenever signal one is at the first position, and signal two is at the first position the arduino should readout the value of the intersection between the two on the array. In this instance (1, 1)

How would one go about creating such an array and functions?

Kind Regards

How would one go about creating such an array

int vals[12][12];

imagine having two different signals going into an arduino

Where? An analog pin?

based on both these signals an array is created.

Populated, maybe, but not created. The array is created at compile time.

12 arbitrary values of signal one and two is chosen and these are placed along the X- and Y- axis of the array respectively.

Arrays don't have axes. They have dimensions. A 2D array has rows and columns.

Whenever signal one is at the first position, and signal two is at the first position the arduino should readout the value of the intersection between the two on the array.

Sorry, you've ceased to make sense. What are these signals, and how are 12 arbitrary values going to mean anything?

I presume you see your array as a spreadsheet, and the value of your two inputs decides which cell to choose, the value of which you want to do something with.

int lookup[12][12] ; // create array (without content. Every cell contains 0)
//OR
int lookup[][] = { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 },
                   { 101, 102, 103, ... }
             :  // and so on until you have written 144 values
                        } }  
  :
// in loop code
X = calculation using analogRead(Xpin) ;
Y = calculation using analogRead(Ypin) ;
Serial.print(lookup[X][Y]);

I can think of a few more way to interpret your question, so try and explain it a little clearer.

const int SIZE = 12;

outputs =
{
{1,2,3,4,5,6,7,8,9,10,11,12},
{1,2,3,4,5,6,7,8,9,10,11,12},
{1,2,3,4,5,6,7,8,9,10,11,12},
{1,2,3,4,5,6,7,8,9,10,11,12},
{1,2,3,4,5,6,7,8,9,10,11,12},
{1,2,3,4,5,6,7,8,9,10,11,12},
{1,2,3,4,5,6,7,8,9,10,11,12},
{1,2,3,4,5,6,7,8,9,10,11,12},
{1,2,3,4,5,6,7,8,9,10,11,12},
{1,2,3,4,5,6,7,8,9,10,11,12},
{1,2,3,4,5,6,7,8,9,10,11,12},
{1,2,3,4,5,6,7,8,9,10,11,12},
};

int inputs_rows{SIZE] = {80, 160, 240, 320, 400, 480, 560, 640, 720, 800, 880, 1024};
int inputs_columns{SIZE] = {80, 160, 240, 320, 400, 480, 560, 640, 720, 800, 880, 1024};

int lower_limit = 0;
for (row = 0; row < SIZE; row++)
{
if (row_value > lower_limit && row_value < inputs_rows[row])
break;
lower_limit = inputs_rows[row];
}

lower_limit = 0;
for (column = 0; column < SIZE; column++)
{
if (column_value > lower_limit && column_value < inputs_column[column])
break;
lower_limit = inputs_column[row];
}

output = outputs[row][column];

Msquare:
I presume you see your array as a spreadsheet, and the value of your two inputs decides which cell to choose, the value of which you want to do something with.

Yes this is how i see it :slight_smile:
thanks

The table I would like to implement in my program would look something like the one attached to this post.

One one analog input pin the horizontal signal will enter as a frequency, and on the vertical a voltage (a fraction of the numbers on the table)

based on the frequency and the voltage a single value should be chosen for further computation before being led to a output pin as a 5v square signal with a certain frequency