dual light sensor version 1 by 力維

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

About CAVEDU 阿吉 - 雜工 (2520 Articles)
CAVEDU 教育團隊 打雜
Contact: Website

Leave a comment

Your email address will not be published.


*