Hi there everyone!
I need your help to improve my code by adding a speed control to be able to change the speed of the servo,
any help is much appreciated!
//SETTINGS
//DELAY
int T1 = 500; // Forward delay in ms
int T2 = 500; // Reverse delay in ms
//BUTTON SETTINGS
int InchStepsL = 5; // Inch rotation degrees 0-160
int InchStepsR = 5; // Inch rotation degrees 0-160
int HoldButton = 3000; // Hold button time for instat full rotation in ms
////SAFE ZONE
//
//int SafeZone = 100; // Safe zone position degrees 0-160
//Â Â Â Â Â Â Â Â Â Â // after power surge
         Â
//CODE
#include <Servo.h>
Servo Left;Â //Left Servo Name
Servo Right; //Right Servo Name
const int LeftServo = 2;Â //Left Servo Pin
const int RightServo = 3; //Right Servo Pin
const int Forward = 4; //Forward Button Pin
const int Reverse = 6; //Reverse Button Pin
const int LOCK = 8; //Lock Pin
const int LeftPot = A0;Â //Left Pot Pin
const int RightPot = A1; //Left Pot Pin
int LeftAngle =Â 0;
int RightAngle = 0;
void setup() {
Â
 Serial.begin(9600);
 pinMode(Forward, INPUT_PULLUP);
 pinMode(Reverse, INPUT_PULLUP);
 pinMode(LOCK, OUTPUT);
Â
//Â LeftAngle = analogRead(LeftPot);
//Â LeftAngle = map(LeftAngle, 1028, 0, 160, 0);
//Â RightAngle = analogRead(RightPot);
//Â RightAngle = map(RightAngle, 1028, 0, 160, 0);
 Serial.print("Left Angle = ");
 Serial.println(LeftAngle);
 Serial.print("Right Angle = ");
 Serial.println(RightAngle);
 Left.attach(LeftServo);
 Right.attach(RightServo);
 Left.write(LeftAngle);
 Right.write(RightAngle);
 delay(1000);
 Left.detach();
 Right.detach();
 digitalWrite(LOCK, HIGH);
Â
}
void loop() {
Â
 if (digitalRead(Forward) == HIGH) {
  Serial.println("FORWARD");
  Serial.println("");
  unsigned long StartF = millis();
 Â
  while (digitalRead(Forward) == HIGH) {
   Serial.println("FORWARD");
   Serial.println("");
  Â
  if (millis() - StartF < HoldButton) {
   digitalWrite(LOCK, LOW);
   Serial.println("LESS THAN 3 SECONDS(FORWARD)");
   Serial.println("");
   RightAngle += InchStepsR;
   LeftAngle += InchStepsL;
   if (RightAngle >= 160) {
    RightAngle = 160;
   }
   if (LeftAngle >= 160) {
    RightAngle = 160;
   }
   Right.attach(RightServo);
   Left.attach(LeftServo);
  Â
   Right.write(RightAngle);
   delay(T2);
   Left.write(LeftAngle);
   delay(500);
   Left.detach();
   Right.detach();
   digitalWrite(LOCK, HIGH);
  Â
  }
  else if (millis() - StartF >= HoldButton) {
   digitalWrite(LOCK, LOW);
   Serial.println("MORE THAN 3 SECONDS(FORWARD)");
   Serial.println("");
   RightAngle = 160;
   LeftAngle = 160;
  Â
   Right.attach(RightServo);
   Left.attach(LeftServo);
  Â
   Right.write(RightAngle);
   delay(T2);
   Left.write(LeftAngle);
  Â
   delay(1000);
   Left.detach();
   Right.detach();
   digitalWrite(LOCK, HIGH);
  Â
  }
 }
 }
 if (digitalRead(Reverse) == HIGH) {
  Serial.println("REVERSE");
  Serial.println("");
  unsigned long StartR = millis();
 Â
  while (digitalRead(Reverse) == HIGH) {
   Serial.println("REVERSE");
   Serial.println("");
 Â
  if (millis() - StartR < HoldButton) {
   digitalWrite(LOCK, LOW);
   Serial.println("LESS THAN 3 SECONDS(REVERSE)");
   Serial.println("");
   RightAngle -= InchStepsR;
   LeftAngle -= InchStepsL;
   if (RightAngle <= 0) {
    RightAngle = 0;
   Â
   }
  Â
   if (LeftAngle <= 0) {
    LeftAngle = 0;
   Â
   }
   Left.attach(LeftServo);
   Right.attach(RightServo);
   Left.write(LeftAngle);
   delay(T1);
   Right.write(RightAngle);
   delay(500);
   Left.detach();
   Right.detach();
   digitalWrite(LOCK, HIGH);
  Â
  }
  else if (millis() - StartR >= HoldButton) {
   digitalWrite(LOCK, LOW);
   Serial.println("MORE THAN 3 SECONDS(REVERSE)");
   Serial.println("");
   RightAngle = 0;
   LeftAngle = 0;
   Left.attach(LeftServo);
   Right.attach(RightServo);
   Left.write(LeftAngle);
   delay(T1);
   Right.write(RightAngle);
   delay(1000);
   Left.detach();
   Right.detach();
   digitalWrite(LOCK, HIGH);
  Â
  }
 }
 }
}