dilluns, 29 d’octubre del 2012

Presa 1

task main ()
{
// definim les variables
int blanc;
int negre;
int tolerancia=7;
int llindar;
int sentit=0;
int distancia=60;

// configuro el sensor d'intensitat
SetSensorColorRed (IN_4);
SetSensorLowspeed (IN_1);
//agafo valor negre
negre=Sensor(IN_4);
llindar= negre+tolerancia;


Wait(1000);
//giro a la dreta durant 1s
OnFwd (OUT_C, 75);
OnRev(OUT_A,75);
Wait(1000);
//agafo blanc
blanc=Sensor(IN_4);
// mentres veu mes gran que llindar
while(true){
  if(Sensor (IN_4)<llindar)
    {
    OnRev(OUT_AC,50);
    Wait(100);
    OnFwd(OUT_A,50);
    OnRev(OUT_C,50);
    Wait(500);
    }//fi if
  else{
    if(SensorUS(IN_1)>distancia)
     {
       OnFwd(OUT_A,75);
       Wait (500);
   
       OnRev(OUT_A,75);
       Wait (500);
     } //fi if
    else
     {
    
     OnFwd(OUT_A,50);
     OnRev(OUT_C,50);
     Wait(200);
     OnFwd(OUT_AC,100);
     Wait(200);
     } //fi else
   } // fi else
} // fi while
} // task