servo speed control

here some code i found that controls a servo using IRremote,

im just wondering what to add to slow the movement of the servo,
and also add a control to interrupt and stop the movement,

#include <Servo.h>
#include <IRremote.h>

unsigned long Value2 = 0xFFE01F; // where XXXXXXXX is on our your remote’s values. We will call this Value 1
unsigned long Value1 = 0xFF609F; // where XXXXXXXX is another button on your remote

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

Servo servo1;

// the setup routine runs once when you press reset:
void setup() {

Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver

// initialize the digital pin as an output.

servo1.attach(10); // attack servo to digital pin 10
}
// the loop routine runs over and over again forever:
void loop() {

if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}

if(results.value == Value1) {
servo1.write(179);
}

if(results.value == Value2) {
servo1.write(1);
}

}

any help would be much appreciated, thanks

You cannot really control the speed of the servo.

What you can do, however, is to make the servo move in small steps, and stop for a while between each step.

If you wanted to make the servo move from one end of its range to the other, quite slowly, you could write something like this.

int first_pos = 1 ;
int last_pos = 179 ;
int idelay = 200 ;

for ( int i = first_pos ;  i<=last_pos ; i++ )
{
    servo.write(i) ;
    delay ( idelay ) ;
}

This will take about 30 seconds to go from one end to the other.

cheers for that, any idea how where about i should put that code??

aeddleston:
cheers for that, any idea how where about i should put that code??

In the logical place its needed?

Servo speed control discussion.