Take a look...



///////////////////////////////
int x;
int IR_center;
int IR_right;
int IR_left;
int IR_BC;
int IR_BR;
int IR_BL;
int IR_Back;
int sharp_center;
int sharp_right;
int sharp_left;
int freespace;
int spraycheck;
int IR_Front;

///////////////////////////////
void Forward()
{
    PORTC = 0b11000011;
    freespace--;
      if (freespace < 0)
      {
       freespace = 0;
      }
}

//////////////////////////
void Right()
{
    PORTC = 0b11000101;
    freespace = freespace + 2;
}

//////////////////////////
void Left()
{
    PORTC = 0b10100011;
    freespace = freespace + 2;
}

////////////////////////
void Back()
{
    PORTC = 0b10100101;
}
MOVIE HERE

///////////////////////
void Stop ()
{
    PORTC = 0b00000000;
}
/////////////////////////////// /////Turret Movement/////////// /////////////////////////////// /////Straight Ahead//////////// void Center () { x = 10; while(x > 0) { PORTB.F0 = 1; Delay_us(1400); PORTB.F0 = 0; Delay_us(25000); x = x - 1; } IR_Center = Adc_Read(1); sharp_center = Adc_Read(0); IR_BC = Adc_Read(2); } ////////////////////////// void FarRight () { x = 10; while(x > 0) { PORTB.F0 = 1; Delay_us(700); PORTB.F0 = 0; Delay_us(25000); x --; } IR_right = Adc_Read(1); sharp_right = Adc_Read(0); IR_BR = Adc_Read(2); } ////////////////////////// void FarLeft() { x = 10; while(x > 0) { PORTB.F0 = 1; Delay_us(2100); PORTB.F0 = 0; Delay_us(25000); x --; } IR_Left = Adc_Read(1); sharp_Left = Adc_Read(0); IR_BL = Adc_Read(2); } /////////////////////////////// //Sort Data And if necessary/// ////Stop you st00pid bot/////// /////////////////////////////// void SortBackValues () { if (IR_BC < IR_BR) { if (IR_BC < IR_BL) { IR_Back = IR_BC; } else { IR_Back = IR_BL; } } else { if (IR_BR < IR_BL) { IR_Back = IR_BR; } else { IR_Back = IR_BL;} } IR_Back = IR_Back + 100; } void SortFront() { if (IR_center 300) { PORTC = 0b11000101; //Right delay_ms(500); freespace = freespace + 2; } if (sharp_right > 250) { PORTC = 0b11000101; //Right delay_ms(500); freespace = freespace + 2; } if (sharp_left > 250) { PORTC = 0b10100011; //Left delay_ms(500); freespace = freespace + 2; } } ////////////////////////// void blow () { x = 40; while(x > 0) { PORTB.F1 = 1; Delay_us(2800); PORTB.F1 = 0; Delay_us(25000); x --; } Center(); FarRight(); x = 40; while(x > 0) { PORTB.F1 = 1; Delay_us(700); PORTB.F1 = 0; Delay_us(25000); x --; } } ////////////////////////// /////////////////////////////// /////Main Portion////////////// /////////////////////////////// void Main () { ADCON1 = 0b10000000; TRISA = 0b00011111; TRISB = 0b00000000; TRISC = 0b00000000; IR_Center = 500; while(IR_Center > 200) { Forward(); Center(); FarRight(); Center(); FarLeft(); see(); SortFront(); SortBackValues(); SortRight(); SortLeft(); SortBack(); } PORTC = 0b00000000; Forward(); delay_ms(100); PORTC = 0b00000000; FarLeft(); Blow(); FarLeft(); Blow(); }
Go back to my page!