task main()
{
	bFloatConversionErrors=true;
	displayTextLine(0, "HT Gyro");
	displayTextLine(1, "Test task");
	displayTextLine(5, "Press enter");
	displayTextLine(6, "to set relative");
	displayTextLine(7, "heading");

	sleep(2000);
	eraseDisplay();

	startTask(gyro_loop);
	while(true)
	{
		if(getXbuttonValue(xButtonEnter))
		{
			gyro_loop_state = CALIBRATION;
			sleep(2000);
		}else if(getXbuttonValue(xButtonLeft))
		{
			gyro_loop_state = STOPPED;
			while(gyro_loop_state!=STOPPED)
				sleep(2000);
			stopTask(gyro_loop);
		}else if(getXbuttonValue(xButtonRight))
		{
			startTask(gyro_loop);
		}else
		{
			sleep(1000);
		}
	}

}
// main task
task main ()
{
  displayCenteredTextLine(0, "HiTechnic");
  displayCenteredBigTextLine(1, "IR Seekr");
  displayCenteredTextLine(3, "Test 1");
  displayCenteredTextLine(5, "Press enter to");
  displayCenteredTextLine(6, "switch between");
  displayCenteredTextLine(7, "600 and 1200 Hz");
  sleep(2000);

  // Create struct to hold sensor data
  tHTIRS2 irSeeker;

  // Initialise and configure struct and port
  initSensor(&irSeeker, S1);

  while(true)
  {
    // You can switch between the two different DSP modes by pressing the
    // orange enter button

    playSound(soundBeepBeep);
    while(bSoundActive)
    {}
    eraseDisplay();

    // display the current DSP mode
    if (irSeeker.mode == DSP_1200)
      displayTextLine(0, "    DC 1200");
    else
      displayTextLine(0, "    DC  600");

    while (true)
    {
      if (getXbuttonValue(xButtonEnter))
      {
        // "Enter" button has been pressed. Need to switch mode

        irSeeker.mode = (irSeeker.mode == DSP_1200) ?  DSP_600 : DSP_1200;
        while(getXbuttonValue(xButtonEnter))
        {
          sleep(1);
        }
        break;
      }

      // Read the sensor data.
      readSensor(&irSeeker);
      displayTextLine(1, "D:%4d %4d 3%d", irSeeker.dcDirection, irSeeker.acDirection, irSeeker.enhDirection);
      displayTextLine(2, "0:%4d %d", irSeeker.dcValues[0], irSeeker.acValues[0]);
      displayTextLine(3, "0:%4d %4d", irSeeker.dcValues[1], irSeeker.acValues[1]);
      displayTextLine(4, "0:%4d %4d %3d", irSeeker.dcValues[2], irSeeker.acValues[2], irSeeker.enhStrength);
      displayTextLine(5, "0:%4d %4d", irSeeker.dcValues[3], irSeeker.acValues[3]);
      displayTextLine(6, "0:%4d %4d", irSeeker.dcValues[4], irSeeker.acValues[4]);
      displayTextLine(7, "Enter to switch");
    }
  }
}
示例#3
0
task main () {
  displayTextLine(0, "HT Gyro");
  displayTextLine(1, "Test 1");
  displayTextLine(5, "Press enter");
  displayTextLine(6, "to set relative");
  displayTextLine(7, "heading");

  sleep(2000);
  eraseDisplay();

  // Create struct to hold sensor data
  tHTGYRO gyroSensor;

  // Initialise and configure struct and port
  initSensor(&gyroSensor, S1);

  time1[T1] = 0;
  while(true) {
    if (time1[T1] > 1000) {
      eraseDisplay();
      displayTextLine(1, "Resetting");
      displayTextLine(1, "offset");
      sleep(500);

      // Start the calibration and display the offset
      sensorCalibrate(&gyroSensor);

      displayTextLine(2, "Offset: %f", gyroSensor.offset);
      playSound(soundBlip);
      while(bSoundActive) sleep(1);
      time1[T1] = 0;
    }

    while(!getXbuttonValue(xButtonEnter)) {
      eraseDisplay();

      displayTextLine(1, "Reading");

      // Read the current rotational speed
      readSensor(&gyroSensor);

      // Read the current calibration offset and display it
      displayTextLine(2, "Offset: %4f", gyroSensor.offset);

      displayClearTextLine(4);
      // Read the current rotational speed and display it
      displayTextLine(4, "Gyro:   %4f", gyroSensor.rotation);
      displayTextLine(6, "Press enter");
      displayTextLine(7, "to recalibrate");
      sleep(100);
    }
  }
}
task main() {
  short raw = 0;
  short nrm = 0;
  bool active = true;

  // Turn the light on
  LSsetActive(LEGOLS);

  displayCenteredTextLine(0, "Lego");
  displayCenteredBigTextLine(1, "LIGHT");
  displayCenteredTextLine(3, "SMUX Test");
  displayCenteredTextLine(5, "Connect SMUX to");
  displayCenteredTextLine(6, "S1 and sensor to");
  displayCenteredTextLine(7, "SMUX Port 1");
  sleep(2000);

  displayClearTextLine(7);
  displayTextLine(5, "Press [enter]");
  displayTextLine(6, "to toggle light");
  sleep(2000);

  while (true) {
    // The enter button has been pressed, switch
    // to the other mode
  	if (getXbuttonValue(xButtonEnter))
  	{
      active = !active;
      if (!active)
        LSsetInactive(LEGOLS);
      else
        LSsetActive(LEGOLS);

      // wait 500ms to debounce the switch
      sleep(500);
    }

    displayClearTextLine(5);
    displayClearTextLine(6);
    raw = LSvalRaw(LEGOLS);
    nrm = LSvalNorm(LEGOLS);
    displayTextLine(5, "Raw:  %4d", raw);
    displayTextLine(6, "Norm: %4d", nrm);
    sleep(50);
  }
}
task main () {
  displayCenteredTextLine(0, "HiTechnic");
  displayCenteredBigTextLine(1, "MAGNETIC");
  displayCenteredTextLine(3, "Field Sensor");
  displayCenteredTextLine(4, "SMUX Test");
  displayCenteredTextLine(5, "Connect SMUX to");
  displayCenteredTextLine(6, "S1 and sensor to");
  displayCenteredTextLine(7, "SMUX Port 1");

  sleep(2000);

  displayCenteredTextLine(5, "Press enter");
  displayCenteredTextLine(6, "to set bias");

  sleep(2000);
  eraseDisplay();

  // Create struct to hold sensor data
  tHTMAG magneticSensor;

	// The sensor is connected to the first port
	// of the SMUX which is connected to the NXT port S1.
	// To access that sensor, we must use msensor_S1_1.  If the sensor
	// were connected to 3rd port of the SMUX connected to the NXT port S4,
	// we would use msensor_S4_3

  // Initialise and configure struct and port
  initSensor(&magneticSensor, msensor_S1_1);

  while(true) {
    eraseDisplay();
    displayTextLine(1, "Resetting");
    displayTextLine(2, "bias");
    sleep(500);

    // Start the calibration and display the offset
    sensorCalibrate(&magneticSensor);

    displayTextLine(2, "Bias: %4d", magneticSensor.bias);
    playSound(soundBlip);
    while(bSoundActive) sleep(1);
    while(getXbuttonValue(xButtonAny)) sleep(1);

    while(!getXbuttonValue(xButtonEnter)) {
      eraseDisplay();

      // Read the sensor data
      readSensor(&magneticSensor);

      displayTextLine(1, "Reading");
      // Display the current calibration value
      displayTextLine(2, "Bias: %4d", magneticSensor.bias);

      displayClearTextLine(4);
      // Display the current magnetic field strength
      displayTextLine(4, "Mag:   %4d", magneticSensor.strength);
      displayTextLine(6, "Press enter");
      displayTextLine(7, "to recalibrate");
      sleep(100);
    }
  }
}