double linearInterpolate(double y, double data[][2])
This declares data to be a pointer to an array of double of unknown length.
In this statement:
for (int i = 0; i < sizeof(data) / (sizeof(data[0][0]) * 2); i++)
sizeof(data) is 2 because data is a pointer.
sizeof(data[0][0]) is 4 because data[0][0] is a double, which is actually a float on a Mega and is therefore 4 bytes and *2 gives 8.
Your for loop executes while i < 2/8 which is zero (because 2/8 is an integer division) and thus loop is never executed.
You should also pass the length of the array to the linearInterpolate function because it has no way of knowing the length of the data array.
There are some assumptions in that code which will also eventually bite you.
- Your code assumes that it will always find a value. If it doesn't, it will return the value of x which has not been initialized and will be a random value on the stack. It happens to be zero in your test code but you can't count on it. Initialize it to -1 and test for that return value.
- If you do find a value, you don't return it immediately. Put return(x) after x has been calculated inside the if statement.
Pete