Robot C-program for Group B-3 (wind), E5 Fall 2002

Tim Cronin

Nathan Landy

Ann Marie Lam

void main(void)
{ 
    int x,y,z;
    int still[2];
    int storm[2];
    int threshold[2];
    int i,j,k;
    printf("\n press start to set still");
    sleep(1.5);
    while(!start_button())
      {
        printf("\n %d %d",analog(2), analog(3));
        sleep(0.5);
    }    
    for(i=0; i<=1; i++)
      {
        still[i]=analog(i+2);
    }
    printf("\n press start to set storm");
    sleep(1.5);
    while(!start_button())
      {
        printf("\n %d %d",analog(2), analog(3));
        sleep(0.5);
    }    
    for(j=0; j<=1; j++)
      {
        storm[j]=analog(j+2);
    }
    for(k=0; k<=1; k++)
      {
        threshold[k]=(still[k]+storm[k])/2;
    }
    printf("\n %d %d",threshold[0], threshold[1]);
    sleep(5.0);
    
    while(8*(threshold[0]+threshold[1])/3>(analog(2)+analog(3)))
     {  
        motor(0,40);
        motor(1,40);  
        printf("\n %d %d",analog(2), analog(3));
            if(z=stop_button())
              {
                ao();
                sleep(3.0);
              }  
            if(x=!digital(7))
              { 
                ao();
                printf("\nouch");
                tone(250.0,0.1);
                tone(225.0,0.1);
                tone(150.0,0.4);
                sleep(0.5);
                motor(0,-50);
                motor(1,-50);
                sleep(2.0);
                motor(0,-50);
                motor(1,50);
                sleep(3.0);
                ao();
              }
            if(y=!digital(8))
              { 
                ao();
                printf("\nouch");
                tone(250.0,0.1);
                tone(225.0,0.1);
                tone(150.0,0.4);
                sleep(0.5);
                motor(0,-50);
                motor(1,-50);
                sleep(2.0);
                motor(0,50);
                motor(1,-50);
                sleep(3.0);
                ao();
            }  
            if(analog(2)>threshold[0])
              {
                motor(0,0);
                motor(1,50);
              } 
            if(analog(3)>threshold[1])
              {
                motor(0,50);
                motor(1,0);
              }        
        
      } 
    ao();
    printf("\n %d %d",analog(2), analog(3));
    printf("         (Ode to Joy)");
    tone(329.6,0.3);
    tone(329.6,0.3);
    tone(349.2,0.3);
    tone(392.0,0.3);
    tone(392.0,0.3);
    tone(349.2,0.3);
    tone(329.6,0.3);
    tone(293.7,0.3);
    tone(261.6,0.3);
    tone(261.6,0.3);
    tone(293.7,0.3);
    tone(329.6,0.3);
    tone(329.6,0.35);
    tone(293.7,0.25);
    tone(293.7,0.6);
    
    tone(329.6,0.3);
    tone(329.6,0.3);
    tone(349.2,0.3);
    tone(392.0,0.3);
    tone(392.0,0.3);
    tone(349.2,0.3);
    tone(329.6,0.3);
    tone(293.7,0.3);
    tone(261.6,0.3);
    tone(261.6,0.3);
    tone(293.7,0.3);
    tone(329.6,0.3);
    tone(293.7,0.35);
    tone(261.6,0.25);
    tone(261.6,0.7);
    
    tone(293.7,0.3);
    tone(293.7,0.3);
    tone(329.6,0.3);
    tone(261.6,0.3);
    tone(293.7,0.3);
    tone(329.6,0.15);
    tone(349.2,0.15);
    tone(329.6,0.3);
    tone(261.6,0.3);
    tone(293.7,0.3);
    tone(329.6,0.15);
    tone(349.2,0.15);
    tone(329.6,0.3);
    tone(293.7,0.3);
    tone(261.6,0.3);
    tone(293.7,0.3);
    tone(196.0,0.6);
    
    tone(329.6,0.3);
    tone(329.6,0.3);
    tone(349.2,0.3);
    tone(392.0,0.3);
    tone(392.0,0.3);
    tone(349.2,0.3);
    tone(329.6,0.3);
    tone(293.7,0.3);
    tone(261.6,0.3);
    tone(261.6,0.3);
    tone(293.7,0.3);
    tone(329.6,0.3);
    tone(293.7,0.35);
    tone(261.6,0.25);
    tone(261.6,0.7);
}