Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
#include "SoR_Utils.h" //includes all the technical stuffint main(void) { //declare variables here int i=1000;//a 'whatever' variable int sensor_left=0;//left photoresistor int sensor_right=0;//right photoresistor int threshold=0;//the larger this number, the more likely your robot will drive straight /****************INITIALIZATIONS*******************/ configure_ports(); // configure which ports are analog, digital, etc. a2dInit(); // initialize analog to digital converter (ADC) a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage /**************************************************/ /*********ADD YOUR CODE BELOW THIS LINE **********/ LED_off();//turn LED on while(1) { //store sensor data sensor_left=a2dConvert8bit(5); sensor_right=a2dConvert8bit(4); //detects more light on left side of robot if(sensor_left > sensor_right && (sensor_left - sensor_right) > threshold) {//go left servo_left(44); servo_right(44); } //detects more light on right side of robot else if(sensor_right > sensor_left && (sensor_right - sensor_left) > threshold) {//go right servo_left(25); servo_right(25); } //light is about equal on both sides else {//go straight servo_left(25); servo_right(44); } delay_cycles(500);//a small delay to prevent crazy oscillations } /*********ADD YOUR CODE ABOVE THIS LINE **********/ return 0;}
I have modified the code to remove the threshold