void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(1, OUTPUT); pinMode(2, OUTPUT); } void loop() { // put your main code here, to run repeatedly: int p1n = analogRead(A0); int p2n = analogRead(A1); int p3n = analogRead(A2); int p4n = analogRead(A3); //sum readings with a weighting to determine position; //divide by 4 to get integer between 1 and 255 for pwm //*edit, this doesnt scale properly int linepos = ((p1n *(-2))+(p2n *(-1))+(p3n)+(p4n *2))/4; //print these so you can check everything is working, delay needs to change for actual machine. Serial.print(linepos); Serial.print(" next "); //send the number to a pin to set pwm, I don't think this would //be particularly effective for the rover though. if (linepos > 0) { analogWrite (1, linepos); } else if (linepos < 0) { analogWrite (2, linepos*(-1)); } else { analogWrite (1, linepos); analogWrite (2, linepos); } delay(2000); }