Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Suggestion on how to change the speed of servo on: October 12, 2012, 04:28:57 pm
Hey guys,
I want to have different speed serving for my servomotor.  I would like to ask how should I do it?  From the sweep code below that I am currently using, if I wanted to adjust the speed do I adjust either the delay or the increment?  Appreciate any helpful feedback.


Servo myservo;  // create servo object to control a servo
     
int 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 < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}
2  Using Arduino / Programming Questions / Re: Modify Sweep Program to Control Servomotor's Position on: September 25, 2012, 08:41:59 am
#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int 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 = 45; pos < 135; pos += 1)  // goes from 45 degrees to 135 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 135; pos>=45; pos-=1)     // goes from 135 degrees to 45 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}


Is there another library aside from servo.h that I could use? 
3  Using Arduino / Programming Questions / Modify Sweep Program to Control Servomotor's Position on: September 22, 2012, 07:54:40 pm
Hi All,
I am a newbie in Arduino programming.  Yesterday, I got my Arduino and Futaba hobby servomotor.  I tried the sweep program in Arduino and it works right.  My question is that is it possible to modify the sweep code such that the loop of servomotor to go from position A to position B will only run for x number of minutes then it will stop at specific position such as position A?  I am not sure if this is even possible.  I tried to research but most of what I've seen related topics are open-ended question and was never answered.  Appreciate any input/advice how can I proceed. 

Thanks
Pages: [1]