2005/C4/ひろし
懐中電灯の光を探すロボット†
#define LIGHT SENSOR_3
#define M OUT_C
#define TIME_ROTE_AROUND 200
int hilight=0;
task main(){
Wait(200);
//init
SetSensor(LIGHT,SENSOR_LIGHT);
SetPower(M,1);
hilight=0;
//go!
findhilight();
gobackbylight();
//gobackbytimer();
}
sub findhilight(){
//find hilight
//init timer
ClearTimer(0);
ClearTimer(1);
//run
OnFwd(M);
while(FastTimer(0)<=TIME_ROTE_AROUND){
int tmp=LIGHT;
if(tmp>=(hilight-5)){
hilight=tmp;
ClearTimer(1);
}
}
//
Off(M);
}
sub gobackbylight(){
//go back to hilight position by hilight
//sonooze
Wait(100);
//run reverse
OnRev(M);
while(LIGHT<=(hilight-5));
Off(M);
}
sub gobackbytimer(){
//go back to hilighted position
int time=FastTimer(1);//最後に明るい場所を通った時から経過した時間
//snooooooooooze
Wait(100);
OnRev(M);
ClearTimer(2);
while(FastTimer(2)<=time);
Off(M);
}