several servoes

hi there, I connect my several servoes to arduino, I use code that is below. if you can, tell whats wrong.
thanks

#include <Servo.h> 
 
Servo myservo; 
 Servo myservo1;
int potpin = 0;  
int val;    
 
void setup() 
{ 
  myservo.attach(9);  
  myservo1.attach(8);
} 
 
void loop() 
{ 
  val = analogRead(potpin);            
  val = map(val, 0, 511, 0, 40);     
  myservo1.write(val);                  
  delay(1500);
  
  val = analogRead(potpin);            
  val = map(val, 0, 511, 0, 0);     
  myservo1.write(val);                  
  delay(1500);
  
  val = analogRead(potpin);            
  val = map(val, 0, 511, 0, 40);     
  myservo.write(val);                  
  delay(1500);
  
  val = analogRead(potpin);            
  val = map(val, 0, 511, 0, 40);     
  myservo.write(val);                  
  delay(1500);
}
val = map(val, 0, 511, 0, 0);

What is this supposed to do?

What do you want your code to do? What does it actually do?

How are you powering it all? Hopefully you have a separate power supply for the servos.

  val = analogRead(potpin);            
  val = map(val, 0, 511, 0, 40);     
  myservo.write(val);                  
  delay(1500);

This is repeated twice in the code

Edited to remove drivel :smiley:

The servo library doesn't require servos to be attached to PWM pins.

lasha:
if you can, tell whats wrong.

No idea what's wrong, because you haven't said.

Does it compile? Does it run? Does it do what you intend?

AWOL:
The servo library doesn't require servos to be attached to PWM pins.

Redacted.
Does Servo lib use it's own PWM then or are servo's controlled some other way?

Does Servo lib use it's own PWM then or are servo's controlled some other way?

Yes. That is why using Servos reduces the number of PWM pins available. The Servo class co-opts the timers for controlling n servos. Each timer co-opted removes the ability to PWM two pins.