|
THS
|
Robots /
HuntMurphyMainC*/
void pickdrop (int color); // pick drop and make sure the correct color ball was found void checkcolor (int color); // pick drop and make sure the correct color ball was found void findlight (void); // find the net by finding the light void rightbumper(void); // spin 90 degrees away from right bumper when right bumper is pressed void leftbumper (void); // spin 90 degrees away from left bumper when left bumper is pressed void controlarm_up (void); // find balls void reset_odometer(void); // reset odometer void spin (int l, int r); // Declare GLOBAL constants used in function main: void blink_display(int dvar1, int dvar2, int dvar3, int dvar4); // display important information
const uint8_t green =0;
uint16_t color1 = 0;
uint16_t color2 = 0;
uint8_t toggle = 0;
uint8_t timer =0;
uint16_t time =0;
uint16_t lightmeter = 0;
uint16_t bluelow = 8;
uint16_t bluehigh = 66;
uint16_t yellowlow = 60;
uint16_t yellowhigh = 110;
uint8_t asrg;
// Declaraion for function "main"
cr8_adc_enable(ADC_CENTER_2);
cr8_adc_enable(ADC_LEFT_1);
// Allocate memory for sensor data structure
cr8_init(cr8); // Declare LOCAL constants used in function main:
cr8_update(cr8); cr8_stopwatch_start(); while(intime) { controlarm_up(); cr8_update(cr8); cr8_set_leds(1,1,0,255); if(cr8->button_play) { cr8_set_leds(1,0,0,255); while(intime) { color1=bluelow; color2=bluehigh; cr8_update(cr8); while((cr8->adc_left2 < color1) || (cr8->adc_left2 >color2)) { cr8_update(cr8); findballs(); pickdrop(); checkcolor(color1, color2); } findlight(); pickdrop(); cr8_update(cr8); } } if(cr8 -> button_advance) { cr8_set_leds(0,1,0,255); while(intime) { color1=yellowlow; color2=yellowhigh; cr8_update(cr8); while((cr8->adc_left2 < color1) || (cr8->adc_left2 >color2)) { cr8_update(cr8); findballs(); pickdrop(); checkcolor(color1, color2); } findlight(); pickdrop(); cr8_update(cr8); } } cr8_update(cr8); } cr8_free(cr8); return(0); }
// End of function main
{
cr8_set_mc_led0(0);// turns off left cm led
cr8_set_mc_led1(1);// turns on right cm led
// turn CCW
while ((cr8 -> bumper_right) && (!cr8->bumper_left) && (safe) && (cr8_stopwatch_time() < time))
{
blink_display(cr8 -> adc_center2, 0, cr8 -> angle, cr8_stopwatch_time());
cr8_drive_direct(-250,250);
cr8_update(cr8);
}
reset_odometer();
// drive CCW a half turn
while ((cr8 -> angle < 45) && (!cr8 -> bumper_right) && (!cr8 -> bumper_left) && (safe) && (cr8_stopwatch_time() < time))
{
blink_display(cr8 -> adc_center2, 0, cr8 -> angle, cr8_stopwatch_time());
cr8_drive_direct(-250,250);
cr8_update(cr8);
}
cr8_update(cr8);
reset_odometer();
return;
}
{
cr8_set_mc_led0(1); // turns on left cm led
cr8_set_mc_led1(0); // turns off right cm led
// turn CW
while ((cr8 -> bumper_left) && (!cr8->bumper_right) && (safe) && (cr8_stopwatch_time() < time))
{
blink_display(cr8 -> adc_center2, 0, cr8 -> angle, cr8_stopwatch_time());
cr8_drive_direct(250,-250);
cr8_update(cr8);
}
reset_odometer();
// turn create CW half turn
while ((cr8->angle>-45)&&(!cr8->bumper_right)&&(!cr8->bumper_left)&&(safe)&&(cr8_stopwatch_time()<time))
{
blink_display(cr8 -> adc_center2, 0, cr8 -> angle, cr8_stopwatch_time());
cr8_drive_direct(250,-250);
cr8_update(cr8);
}
cr8_update(cr8);
reset_odometer();
return;
}
{
if (cr8_stopwatch_time() >= time + 3)
{
lcd_print_4vars(dvar1, dvar2, dvar3, dvar4, true, false);
time = cr8_stopwatch_time();
cr8_set_leds(0,togglegreen%2,0,255);
toggle++;
cr8_update(cr8);
}
return;
}
// resets values of odometer. Sets time, toggle and angle to zero.
{
cr8_update(cr8);
time = 0;
toggle = 0;
cr8 -> angle = 0;
cr8_update(cr8);
return;
}
// lift the contraption up
{
cr8_cricket_servo_set(1, 0);
cr8_delay(1000);
cr8_cricket_servo_set(0, 120);
return;
}
|