示例#1
0
 /*
  =============================================================================
  main task with some testing code

 */
task main() {
  int _raw = 0;
  int _processed = 0;

  // Standard range is set to short range
  bool shortrange = true;

  nNxtButtonTask  = -2;

  eraseDisplay();

  nxtDisplayCenteredTextLine(0, "HiTechnic");
  nxtDisplayCenteredBigTextLine(1, "EOPD");
  nxtDisplayCenteredTextLine(3, "Test 1");
  nxtDisplayCenteredTextLine(5, "Press enter to");
  nxtDisplayCenteredTextLine(6, "switch between");
  nxtDisplayCenteredTextLine(7, "ranges");
  wait1Msec(2000);
  eraseDisplay();

  // Set the sensor to short range
  HTEOPDsetShortRange(HTEOPD);

  while(true) {
    if (time1[T1] > 1000) {
      if (shortrange == false) {
        // set the sensor to short range and display this
        HTEOPDsetShortRange(HTEOPD);
        nxtDisplayClearTextLine(1);
        nxtDisplayTextLine(1, "Short range");
        shortrange = true;
      } else {
        // set the sensor to long range and display this
        HTEOPDsetLongRange(HTEOPD);
        nxtDisplayClearTextLine(1);
        nxtDisplayTextLine(1, "Long range");
        shortrange = false;
      }
	    PlaySound(soundBeepBeep);
	    while(bSoundActive)
      time1[T1] = 0;
    }

    while(nNxtButtonPressed != kEnterButton) {
      // Read the raw sensor value
      _raw = HTEOPDreadRaw(HTEOPD);

      // read the processed value which is linear with
      // the distance detected.  Use the processed value
      // when you want to determine distance to an object
      _processed = HTEOPDreadProcessed(HTEOPD);
      nxtDisplayClearTextLine(3);
      nxtDisplayClearTextLine(4);
      nxtDisplayTextLine(4, "Proc:  %4d", _processed);
      nxtDisplayTextLine(3, "Raw :  %4d", _raw);
      wait1Msec(50);
    }
  }
}
task main(){
  initializeRobot();
  // wait for start of tele-op phase
  waitForStart();
  //actual control of the robot
  int _raw = 0;
  int _processed = 0;

  // Set the sensor to short range
  HTEOPDsetShortRange(HTEOPD);
  while (true){

		getJoystickSettings(joystick);
		//code for robot panning controlled by the left joystick
		if(joystick.joy1_y1 > zero){ //forwards
			ySet(joystick.joy1_y1);
		}else if(joystick.joy1_y1 < -zero){ //backwards
			ySet(joystick.joy1_y1);
		}else if(joystick.joy1_x1 < -zero){ //left
			xSet(joystick.joy1_x1);
		}else if(joystick.joy1_x1 > zero){ //right
			xSet(joystick.joy1_x1);
		}else if(joystick.joy1_x2 < -zero){ //left turn
			turn(joystick.joy1_x2);
		}else if(joystick.joy1_x2 > zero){ //right turn
			turn(joystick.joy1_x2);
		}else{
			ySet(0);
		}


}
task main()
{
	servo[topServo] = 235;
	initializeRobot();

		int _raw = 0;
  int _processed = 0;

  // Set the sensor to short range
  HTEOPDsetShortRange(HTEOPD);

  while(true){
	  // Read the raw sensor value
    _raw = HTEOPDreadRaw(HTEOPD);
    // read the processed value which is linear with
    // the distance detected.  Use the processed value
    // when you want to determine distance to an object
    _processed = HTEOPDreadProcessed(HTEOPD);
    nxtDisplayClearTextLine(3);
    nxtDisplayClearTextLine(4);
    nxtDisplayTextLine(4, "Proc:  %4d", _processed);
    nxtDisplayTextLine(3, "Raw :  %4d", _raw);
    wait1Msec(50);
    if (_processed > 41) {
      LSsetActive(LEGOLS); // turn light on
      PlaySound(soundBeepBeep);
      while(bSoundActive){};
      LSsetInactive(LEGOLS); // turn light off
    } // if ball close
  }
}