array of variables

I am trying to initialize the position of four legs on my quadruped. I have the servo values in an array and would like to set them with a loop structure. the legs are labels: leg1, leg2, leg3 and leg4. Right now I have them initialized like so:

leg1.write(90); // set leg1 to neutral position
leg2.write(90); // set leg2 to neutral position
leg3.write(95); // set leg3 to neutral position
leg4.write(98); // set leg4 to neutral position

I would like to perform this in a loop like:

for (int count=0;count<4;count++)
{
leg(count).write(servo_value[count]);
}

where servo_value is the setting for the servos.

whats stopping you

lloyddean: Shouldn't be too hard

I think you need an array of servos.

// <http://arduino.cc/forum/index.php/topic,156278.0.html>

#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
#else
  #include "WProgram.h"
#endif

#include <Servo.h> 

#define ENTRIES(ARRAY)          (sizeof(ARRAY) / sizeof(ARRAY[0]))

// IMPORTANT NOTE: Set these to YOUR pin numbers
const uint8_t   pinServo0   = 1; // set pin number this servo connected to.
const uint8_t   pinServo1   = 2; // set pin number this servo connected to.
const uint8_t   pinServo2   = 3; // set pin number this servo connected to.
const uint8_t   pinServo3   = 4; // set pin number this servo connected to.

struct servo_tt
{
    const uint8_t   _pin;
    Servo           _servo;
    int             _position;

    servo_tt(uint8_t const pin, int const position)
        : _pin(pin), _servo(), _position(position)
    {}
};

servo_tt servos[] =
{
      { pinServo0, 90 }
    , { pinServo1, 90 }
    , { pinServo2, 95 }
    , { pinServo3, 95 }
};
 
void loop() 
{ 
    // ... your positioning code here ...

    // ...  and then to will write the servo position data to the servo ...
    for ( int i = ENTRIES(servos); i--; )
    {
        Servo&  servo       = servos[i]._servo;
        int     position    = servos[i]._position;
        servo.write(position);
 
        delay(15UL);
    }
} 

void setup() 
{ 
    for ( int i = ENTRIES(servos); i--; )
    {
        const uint8_t   pin     = servos[i]._pin;
        Servo&          servo   = servos[i]._servo;
        servo.attach(pin);
    }
}

Thanks guys, I figured it out. As usual, I was making it more difficult than it had to be.