#include Servo qservo; Servo wservo; int q=130,w=180,e=10,r=50,t=40; int Pins[] = {2, 3, 4, 5, 6, 7,8,9,10,11,12,13}; int x1,y1; long leftcount,rightcount; bool left,right; int gap; void setup() { w=190; qservo.attach(9); wservo.attach(10); qservo.write(q); wservo.write(w); leftcount=0; rightcount=0; left=0; right=0; Serial.begin(9600); for(int thisPin=0;thisPin < 12; thisPin++) { pinMode(Pins[thisPin], OUTPUT); pinMode(22,INPUT); pinMode(23,INPUT); } } void loop() { qservo.write(q); wservo.write(w); x1 = digitalRead(22); y1 = digitalRead(23); if(x1==1) { left=1; } if (y1==1) { right=1; } if(x1==0 && left==1) { left=0; leftcount++; } if(y1==0 && right==1) { right=0; rightcount++; } gap=leftcount-rightcount; if(gap>5) { q=60; w=70; } if((rightcount-leftcount)>5) { q=130; w=70; } if(gap<=5&& gap>=-5){ q=85-gap*10; } if(gap>15||gap<-10) { setup(); } }