Problem with servo code

So this is my first ever attempt at using an Arduino and I am trying to control two servos at once. I found code to rotate one and thought I could just duplicate the code for the other pin and servo but the compiler doesn't like it.

What is wrong with it and what is the correct way to code it?

int servopin =2;
int pulse = 1500;

int servopin =3;
int pulse = 1500;

void setup()

{

pinMode(2, OUTPUT);
Serial.begin(9600);
pinMode(3, OUTPUT);
Serial.begin(9600);

}

void loop()
{
digitalWrite(2, HIGH);
delayMicroseconds(pulse);
digitalWrite(2, LOW);
delay(20);
digitalWrite(3, HIGH);
delayMicroseconds(pulse);
digitalWrite(3, LOW);
delay(20);
}

You have two children.
Do you call them both George?

And anyway the sensible way to drive servos is to use the Servo library.

Steve

TolpuddleSartre:
You have two children.
Do you call them both George?

LOL I get you. :smiley:

I think , you have to use only pin 3 5 6 9 10 et 11 OUTPUT pwm only

Pascal7:
I think , you have to use only pin 3 5 6 9 10 et 11 OUTPUT pwm only

I think know you're wrong.

slipstick:
And anyway the sensible way to drive servos is to use the Servo library.

Steve

Just Googled this and yes, I see what you mean, a lot easier!! :slight_smile: