Controlling servo motor with arduino

AWOL:
And does that do what you want?

my full code is:

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
float pos = 0;    // variable to store the servo position 

void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
 
void loop() 
{ 
  for(pos = 0; pos <= 40; pos ++)
  {
    float pos_sin = sin(PI*pos/40);
    myservo.write(40*pos_sin);
    delay(20);
  } 
  for(pos = 40; pos>=0; pos --)    
  {                                
   float pos_sin = sin(PI*pos/40);
    myservo.write(40*pos_sin);
    delay(20);
  } 
}

the pos variable increases/decreases by one.
So that means for one cycle (0deg to 40deg to 0deg) executes each for loop 40 times. Since each execution takes 20/1000seconds, 24020/1000=1.6seconds should be the amount of time it takes for one cycle to occur. I compiled this code, but it's definitely faster than the 1.6 seconds. I'll take a look at my code again, but I don't currently see why it's doing this.

pyroknife:

AWOL:
And does that do what you want?

my full code is:

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

float pos = 0;    // variable to store the servo position

void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop()
{
  for(pos = 0; pos <= 40; pos ++)
  {
    float pos_sin = sin(PIpos/40);
    myservo.write(40
pos_sin);
    delay(20);
  }
  for(pos = 40; pos>=0; pos --)   
  {                               
   float pos_sin = sin(PIpos/40);
    myservo.write(40
pos_sin);
    delay(20);
  }
}




the pos variable increases/decreases by one. 
So that means for one cycle (0deg to 40deg to 0deg) executes each for loop 40 times. Since each execution takes 20/1000seconds, 2*40*20/1000=1.6seconds should be the amount of time it takes for one cycle to occur. I compiled this code, but it's definitely faster than the 1.6 seconds. I'll take a look at my code again, but I don't currently see why it's doing this.

...
I didn't need the second for loop. That's why.