光を追いかけるロボット

工夫した点:なかなか思いどおりにプログラムが動いてくれませんでした

------------------------------------------------------

int lightmax;    
int timemax; 
   
task main ()
{
        SetSensor(SENSOR_1, SENSOR_LIGHT);

        while (true)
        {
                lightmax = 0;
                timemax = 0;

                ClearTimer(0);                                   
                while ( Timer(0) <= 50 )
                {
                        OnFwd(OUT_A);
                        OnRev(OUT_C);
                        if (SENSOR_1 >= lightmax)
                        {
                                lightmax = SENSOR_1 ;
                                ClearTimer(1);                  
                        }
                }
                timemax = Timer(1);
                ClearTimer(0);                                   
                OnRev( OUT_A );
                OnFwd( OUT_C );
                until( Timer(0) >= timemax );
                OnFwd(OUT_A + OUT_C);
                Wait(50);
        }
}

---------------------------------------------------------