Need help in arduino code to slow down servo

hi guys !

first time posting here and I would like your help…

I,m presently working on a robot project and found an Arduino code to control a servo triggered by a push button… it works great but I need to slow the servo down in it,s movements… I think I need to use the delay fonction but I am unsure where I should put it in the code that I have… here is the code:

#include <Servo.h>
const byte switchPinA = 2; //active low
//const byte switchPinB = 3; //active low
const byte servoPin = 9;
Servo servo;
byte switchAstate = HIGH;
//byte switchBstate = LOW;
byte servoPos = 1;
byte posA = 1; // new
byte posB = 180; // new

void setup() {
pinMode(switchPinA, INPUT_PULLUP);
// pinMode(switchPinB, INPUT_PULLUP);
servo.attach(servoPin);

}

void loop () {
readButtons();
moveServo();
}

void readButtons() {
switchAstate = digitalRead(switchPinA);
// switchBstate = digitalRead(switchPinB);
}

void moveServo() {
if (switchAstate == LOW) {
if (servoPos == posA) { // new
servoPos = posB;
delay(2000);

 }
 else { 
   servoPos = posA;
 }
 switchAstate = HIGH; // new

}
// if (switchBstate == LOW) {
// servoPos = 1;
// }

any help or suggestions would be appreciated

thanks !!

Hey @derepentignymarc

Welcome to RobotShop Community!

We have found a nice library which includes everything you need to slow down a servo:
https://forum.arduino.cc/index.php?topic=61586.0