IR Sharp acquisition through array

Dear all,

In my project, i have an IR sensor mounted on a pan servo.

The goal is to move the pan servo from 0 to 180° (it's done).

How could i realize the next points ? :

For each degre, i want to grab the distance from the IR sensor within an array.
Doing the same for the pan servo ( dimension array = 2).
I mean one array for the distance (180 values) and the same for the servo (180 values).

Once i have the distance:f(degre), i would like to extract the longest distance, associated to the degre of the pan servo.
And at least moving the rc car based on the angle of the pan servo.

How can i achieve this ?

Anyone can help me ?

Thanks for your help and support.

Chris

Do you mean something like:

int distances[181];

int minDistanceIndex = 0;
for (int i=0; i<181; i++) {
    servo.write(i);
    delay(20); // Give the servo time to move and settle
    distances[i] = distance();
    if (distances[1] < distances[minDistanceIndex])
        minDistanceIndex = i;
}
// Closest object is at 'minDistanceindex' degrees

Save the current index and the current minimum (or maximum) and you save a whole lot of memory - I don't see an array is necessary

Hello John and AWOL,

Thanks a lot for your help, it was really usefull.

Regards,

Chris