I was able to make the change to the code and added reverse option, after random flow and very smooth ramp up and down it turns reverse slowly for seconds and then ramp up and down again,
#include <Servo.h>
#include <stdlib.h>
const int servoPin1 = 9;
const int servoPin2 = 10;
const int potentiometerPin = A0;
Servo servo1;
Servo servo2;
void setup() {
servo1.attach(servoPin1);
servo2.attach(servoPin2);
randomSeed(analogRead(0));
}
void loop() {
int potVal = analogRead(potentiometerPin);
int pwmVal = map(potVal, 0, 1023, 1100, 1900);
// Determine the random step size for ramping, not more than 30% of the range
int maxStep = (1900 - pwmVal) * 0.3;
int step = random(1, maxStep + 1);
// Ramp up
for (int i = pwmVal; i <= 1900; i += step) {
servo1.writeMicroseconds(i);
servo2.writeMicroseconds(i);
delay(150);
}
// Ramp down
for (int i = 1900; i >= pwmVal; i -= step) {
servo1.writeMicroseconds(i);
servo2.writeMicroseconds(i);
delay(150);
}
// Random step size for reverse ramping, not more than 10% of the range
int reverseSpeedLimit = 0.15; // Adjust this value to control the maximum reverse speed
int maxStepReverse = (pwmVal - 1100) * reverseSpeedLimit;
int stepReverse = random(1, maxStepReverse + 1);
// Ramp up in reverse
for (int i = pwmVal; i >= 1100; i -= stepReverse) {
servo1.writeMicroseconds(i);
servo2.writeMicroseconds(i);
delay(200);
}
}