// LED int LED = 4; //Photo Resistors int photocellLEFT = 1; //left facing photocell sensor int photocellRIGHT = 3; //Turnaround photocell sensor //Motors int leftMOTORpin = 0; // connect leftMotor to pin 0 (PWM pin) int rightMOTORpin = 1; // connect rightMotor to pin 1 (PWM pin) int rightMOTORspeed; int leftMOTORspeed; int leftMOTORratio; int rightMOTORratio; void setup() { analogWrite (LED, HIGH); } void loop(void) { //here we define the speed of the left and right motors as the ratio of brightness between the //two photocells. As the photocell on one side gets brighter, it slows down, turning //the robot in that direction. rightMOTORratio = (analogRead(photocellLEFT) / analogRead(photocellRIGHT)); leftMOTORratio = (analogRead(photocellRIGHT) / analogRead(photocellLEFT)); //this part turns our ratio into a usable speed for our motors leftMOTORspeed = (leftMOTORratio * 255); rightMOTORspeed = (rightMOTORratio * 255); //and this writes that value to the pin analogWrite(leftMOTORpin, leftMOTORspeed); analogWrite(rightMOTORpin, rightMOTORspeed); }