Controlling 30 servos..

Hi PaulS,

I'm using standards servos, 0 to 180. I just need to control 30 servos, by USB. The speed is not to important...

I have this code working with 6 servos, "a" to "f" is the identifier servo and "0" to "180" is the position value.
But I don't know how to "scale" this to up 30 servos..

#include <Servo.h>
#define SERVO_2_PIN 2
#define SERVO_3_PIN 3
#define SERVO_4_PIN 4
#define SERVO_5_PIN 5
#define SERVO_6_PIN 6
#define SERVO_7_PIN 7

Servo g_servo2,g_servo3,g_servo4,g_servo5,g_servo6,g_servo7;

void setup()
{
pinMode(SERVO_2_PIN, OUTPUT);
pinMode(SERVO_3_PIN, OUTPUT);
pinMode(SERVO_4_PIN, OUTPUT);
pinMode(SERVO_5_PIN, OUTPUT);
pinMode(SERVO_6_PIN, OUTPUT);
pinMode(SERVO_7_PIN, OUTPUT);
g_servo2.attach(SERVO_2_PIN);
g_servo3.attach(SERVO_3_PIN);
g_servo4.attach(SERVO_4_PIN);
g_servo5.attach(SERVO_5_PIN);
g_servo6.attach(SERVO_6_PIN);
g_servo7.attach(SERVO_7_PIN);
Serial.begin(9600);
}

void loop()
{
static int val = 0;

if (Serial.available())
{
char ch = Serial.read();

switch(ch)
{
case '0'...'9':
val = val * 10 + ch - '0';
break;
case 'a':
g_servo2.write(val);
val = 0;
break;
case 'b':
g_servo3.write(val);
val = 0;
break;
case 'c':
g_servo4.write(val);
val = 0;
break;
case 'd':
g_servo5.write(val);
val = 0;
break;
case 'e':
g_servo6.write(val);
val = 0;
break;
case 'f':
g_servo7.write(val);

val = 0;
break;
}
}
//Servo::refresh(); // Should try to call this every 20 ms to insure servo stays set
}

Thank you!
Rafael.