工程筆記本 / NXC/RobotC/C++ for Lego robot

NXC/RobotC/C++ for Lego robot

dual light sensor version 1 by 力維

CAVEDU 阿吉 - 雜工📅 2009-09-12👁 23
int W1,B1,WB1;
int W2,B2,WB2;
sub go(int pwr1,int pwr2){
  //while(true){
    OnFwd(OUT_B,pwr1);
    OnFwd(OUT_C,pwr2);
    Wait(100);
    Off(OUT_BC);
  //}
}
sub detect(){
  while(true){
    if(Sensor(S1)
      go(40,40);
    else if(Sensor(S1)>WB1&&Sensor(S2)>WB2)
      go(40,40);
    else if(Sensor(S1) WB2)
      go(0,40);
    else go(40,0);
  }
}
task xxx(){
  until(Sensor(S3)==1);
    B1=Sensor(S1);
    W2=Sensor(S2);
    PlayTone(440,100);
    Wait(200);
  until(Sensor(S4)==1);
    W1=Sensor(S1);
    B2=Sensor(S2);
    PlayTone(440,100);
    Wait(200);
  WB1=(W1+B1)/2;
  WB2=(W2+B2)/2;
  NumOut(20,LCD_LINE4,W1);
  NumOut(45,LCD_LINE4,B1);
  NumOut(70,LCD_LINE4,WB1);
  NumOut(20,LCD_LINE5,W2);
  NumOut(45,LCD_LINE5,B2);
  NumOut(70,LCD_LINE5,WB2);
  Wait(2000);
  detect();
}
task main(){
  SetSensorLight(S1);
  SetSensorLight(S2);
  SetSensorTouch(S3);
  SetSensorTouch(S4);
  start xxx;
}

相關文章 📎

留言 💬 (0)

還沒有留言,來當第一個。