Pleas, my robot is very jagety and in eficient at running. i would love some help to improve on my code!
#include <Servo.h>
Servo motorLeft;
Servo motorRight;
int LIGHT = 13;
int pRL = 2;
int pRM = 1;
int pRR = 0;
int RL;
int RM;
int RR;
void setup(void) {
motorLeft.attach(9);
motorRight.attach(10);
Serial.begin(9600);
}
void loop(void) {
digitalWrite(LIGHT, HIGH);
RL = analogRead(pRL);
RM = analogRead(pRM);
RR = analogRead(pRR);
//RL = 1023 - RL;
//RM = 1023 - RM;
//RR = 1023 - RR;
if (RM < (RL-25) || RM > (RL+25) && RM < (RR-25) || RM > (RR+25)){
Serial.print("MID =");
Serial.println(RM);
motorLeft.write(60);
motorRight.write(120);
}
if(RM > (RL-25) && RM < (RL+25)){
motorLeft.write(60);
motorRight.write(60);
Serial.print("LEFT = ");
Serial.println(RL);
}
if(RM > (RR-25) && RM < (RR+25)){
Serial.print("RIGHT = ");
Serial.println(RR);
motorLeft.write(120);
motorRight.write(120);
}
//Serial.print("PRL = ");
//Serial.println(RL);
//Serial.print("PRM = ");
//Serial.println(RM);
//Serial.print("PRR = ");
//erial.println(RR);
delay(100);
}