買書捐殘盟

2013年4月14日 星期日

UltraSonicSensor應用-保護眼睛的守護神


NXT ,保護眼睛的守護神!
當超音波偵測到前方人體離電視太近的時候,系統發出Light光線及聲音警告。
   
[機構]

[程式]
 #define sonic_sensor IN_1
#define touch_sensor IN_2
#define light_sensor IN_3
#define touch SENSOR_2
#define MotorOut OUT_B
#define length 150

long tick;


void WaitSEC3()
{
   tick=CurrentTick();
   while(CurrentTick()<(tick+3000))
   {
       PlayTone(880,50);
       Wait(950);
   }
   Wait(1000);
}




task main()
{
    SetSensorTouch(touch_sensor);
    ResetTachoCount(MotorOut);
    SetVolume(4);
    SetSensorLight(light_sensor,false);
    SetSensorLowspeed(sonic_sensor);
    WaitSEC3();
}


task MotorRotateFn()
{
   Follows(main);
   while(touch==0)
   {
      RotateMotorPID(MotorOut,10,90,40,40,90);    //右轉
      Wait(100);
      RotateMotorPID(MotorOut,10,-170,40,40,90);  //左轉
      Wait(100);
      RotateMotorPID(MotorOut,10,80,40,40,90);    //右轉
   }
   Off(MotorOut);
   StopAllTasks();
}

task DetectFn()
{
   Follows(main);
   while(true)
   {
     if(SensorUS(sonic_sensor) <length{
       PlayTone(500,50);
       SetSensorLight(light_sensor,true);
       Wait(50);
       SetSensorLight(light_sensor,false);
       Wait(50);
     }
   }
}
[影片]                                  

沒有留言:

張貼留言