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);
	
}

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2005-12-02 (金) 19:40:23