Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 2 Guests are viewing this topic.
int main(void) { //declare variables here //int i=250;//a 'whatever' variable int sensor_left=0;//left photoresistor int sensor_right=0;//right photoresistor int threshold=8;//the larger this number, the more likely your robot will drive straight 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 LED_off();//turn LED on while(1) { // Servo Test Code int i=250; while(i>0) { servo_left(40); i--; } i=250; while(i>0) { servo_left(24); i--; } // end Servo Test Code //rprintf("Initialization Complete\r\n"); //output message to serial (use hyperterminal) //print("Hello, World! Read My Analog: %u\r\n", sensor_0); delay_cycles(500);//a small delay to prevent crazy oscillations } return 0; }
//declare variables here //int i=250;//a 'whatever' variable int sensor_left=0;//left photoresistor
//declare variables here int i=250;//a 'whatever' variable int sensor_left=0;//left photoresistor
int main(void){ configure_ports(); // configure which ports are analog, digital, etc. while(1) { PORTD = 0xFF; // set all portD pins high (pins 2:6, 11:13) delay_cycles(2000); PORTD = 0x00; //set all portD pins low delay_cycles(2000); } return 0;}
Code: [Select]//declare variables here //int i=250;//a 'whatever' variable int sensor_left=0;//left photoresistorshould readCode: [Select]//declare variables here int i=250;//a 'whatever' variable int sensor_left=0;//left photoresistorat first glancethe // shouldnt be in front of the variable declaration, im surprised it compiled (unless your compiler realizes dynamic declarations?)
A great idea for a first attempt with any new microcontroller system is the microcontroller equivalent of 'Hello World' - the flashing LED. Simple to set up and code, and gives great feedback as to whether the device is being programmed ok. Do something like:Code: [Select]int main(void){ configure_ports(); // configure which ports are analog, digital, etc. while(1) { PORTD = 0xFF; // set all portD pins high (pins 2:6, 11:13) delay_cycles(2000); PORTD = 0x00; //set all portD pins low delay_cycles(2000); } return 0;}Even if you don't have an LED to hand this should be easy to check with a meter. You may need higher or lower values of delay_cycles() to get a sensible time for testing.If everything on the computer side indicates ok during programming it is likely the device has been programmed.Your code looks ok, but you only change the value for servo_left() , so only one servo should react. According to the photovore code that should be attached to PORTD,0 = pin 2 of the microcontroller. The voltage you see on this pin when running servos is likely to be fairly meaningless, but values should be clearly defined 5V or 0V when running the code posted above. Suggest you try this first and see if it checks out ok.