[[2016a/Member]]

*ロボット本体の説明 [#m01daee5]

*プログラム [#c67d1a25]

#define LIGHT 39
#define turn_left1 OnFwd(OUT_C); OnRev(OUT_A);
#define turn_left2 OnFwd(OUT_C); Off(OUT_A);
#define turn_right1 OnFwd(OUT_A); OnRev(OUT_C);
#define turn_right2 OnFwd(OUT_A); Off(OUT_C);
#define go OnFwd(OUT_AC);
#define sound PlaySound(SOUND_FAST_UP);

sub fowerd()
{
  sound;
  OnFwd(OUT_AC);
  Wait(40);
  Off(OUT_AC);
}

sub left()
{
  sound;
  turn_left1;
  Wait(30);
  Off(OUT_C);
}

sub line()
{
int ch=0;
  SetSensor(SENSOR_2,SENSOR_LIGHT);
  ClearTimer(0);
  while(ch==0)
  {
    if(FastTimer(0)>40)
    {
     Off(OUT_AC);
     Wait(100);
     ClearTimer(0);
     ch=1;
    }

	if (SENSOR_2 < LIGHT){
	turn_left1;
	}
    	else if (SENSOR_2 < LIGHT + 3){
	
	turn_left2;
	}
	else if (SENSOR_2 < LIGHT + 6){
	ClearTimer(0);
	go;
	}
	else if (SENSOR_2 < LIGHT + 9){
	ClearTimer(0);
	turn_right2;
	}
	else
	{
	ClearTimer(0);
	turn_right1;
	}
   Wait(3);
  }
}

task main()
{
   line();
   fowerd();
   line();
   fowerd();
   line();
   fowerd();
   line();
   left();
   line();
   sound;
   turn_right1;
   Wait(30);
   OnFwd(OUT_AC);
   Wait(150);
   Off(OUT_AC);
}



トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS