Knob with speed limit

can i add speed limit to this code?

Thanks

What sort of servo are you using ? A proper one or a continuous rotation one ?

If the latter, then you can limit the top speed by changing the maximum value output in the map() function to less than 179. If it is a proper sevo then I don't understand the question.

Hi,
This is the servo Im using:

What i want is when i turn the knob all the way, the servo will go slower to its final position and not at full speed

Thanks

Would it be OK if it moved slowly at all times, which would be fairly easy ?

I think this might work but I can't test it since my last arduino is tied up in a project right now.

// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
 
int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

int speed = 5;

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

}
 
void loop()
{
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  if( val > myservo.read() + speed) myservo.write( myservo.read() + speed) ;
  else
  if (val < myservo.read() - speed) myservo.write( myservo.read() - speed) ;
  else  myservo.write(val);                  // sets the servo position according to the scaled value
 
  delay(15);                           // waits for the servo to get there
}

Thanks, this code works,
however i need it slower than "1"
i rtied "0.5" it doesnt work

Where did you put 0.5 instead of 1 ?

int speed = 0.5;

JoZee:
int speed = 0.5;

Integers are whole numbers without decimal points.

...R

so 1 in the minimum value?

JoZee:
so 1 in the minimum value?

In this case, yes. You could use writeMicroseconds instead of write - it'll give you more granular control. You'd need to change the range on the map appropriately though.

For a crude but simpler option, just increase the size of the delay; just be aware that it'll be less responsive.