task main () {
  displayCenteredTextLine(0, "Mindsensors");
  displayCenteredBigTextLine(1, "TMUX");
  displayCenteredTextLine(3, "SMUX Test");
  displayCenteredTextLine(5, "Connect SMUX to");
  displayCenteredTextLine(6, "S1 and TMUX to");
  displayCenteredTextLine(7, "SMUX Port 1");
  sleep(2000);

  while (true) {
    eraseDisplay();
    displayTextLine(0, "MS Touch MUX");

    // Get the raw data from the sensor, this is not processed
    // by the driver in any way.
    displayTextLine(1, "Raw: %d", 1023 - HTSMUXreadAnalogue(MSTMUX));

    // Go through each possible touch switch attached to the TMUX
    // and display whether or not is active (pressed)
    for (short i = 1; i < 4; i++) {
      if (MSTMUXisActive(MSTMUX, i))
        displayTextLine(i+2, "Touch %d: on", i);
      else
        displayTextLine(i+2, "Touch %d: off", i);
    }

    // Display the binary value of the active touch switches
    // 0 = no touch, 1 = touch 1 active, 2 = touch 2 active, etc.
    // touch 1 + touch 2 active = 1 + 2 = 3.
    displayTextLine(7, "Status: %d", MSTMUXgetActive(MSTMUX));
    sleep(50);
  }
}
task main(){

  // This struct holds all the sensor related data
  tDIMC compass;

  displayCenteredTextLine(0, "Dexter Ind.");
  displayCenteredBigTextLine(1, "dCompass");
  displayCenteredTextLine(3, "Test 1");
  displayCenteredTextLine(5, "Connect sensor");
  displayCenteredTextLine(6, "to S1");
  sleep(2000);
  eraseDisplay();

  // Fire up the compass and initialize it. Only needs to be done once.
  if (!initSensor(&compass, DIMC))
    playSound(soundException);

  sleep(100);
  while (true){

    // Read the Compass
    if (!readSensor(&compass))
      playSound(soundException);

    displayCenteredBigTextLine(2, "%3.2f", compass.heading);
    displayTextLine(5, "%d", compass.axes[0]);
    displayTextLine(6, "%d", compass.axes[1]);
    displayTextLine(7, "%d", compass.axes[2]);
    sleep(50);
  }
}
Esempio n. 3
0
//function to get passenger's current y location from numeric keypad
int get_passenger_location_y(){

	int keys = 0;
	unsigned byte key[] = {0};
	int number = 0;
	string output;

	eraseDisplay();
	displayCenteredTextLine(0, "Enter y-location");
	displayTextLine(1, "-------------------");
	displayTextLine(5, "-------------------");

	while (true){
		if (!MSNPscanKeys(MSNP, keys, key[0], number))
			stopAllTasks();

		if ((number>=0)&&(number<20)){
			//if (number == 8){number = 0;}
			displayTextLine(3, "Numpad Key: %d", number);
			wait1Msec(1000);
			sleep(100);
			return number;
			break;
		}

	}
}
task main() {
  short raw = 0;
  short nrm = 0;

  nNxtButtonTask  = -2;

  eraseDisplay();
  displayTextLine(0, "Dexter Industries");
  displayCenteredBigTextLine(1, "dFlex");
  displayCenteredTextLine(3, "Test 1");
  displayCenteredTextLine(5, "Connect sensor");
  displayCenteredTextLine(6, "to S1");
  sleep(2000);

  eraseDisplay();
  displayTextLine(0, "dFlex Sensor");

  while (true) {
    displayClearTextLine(5);
    displayClearTextLine(6);

    // Get the raw value from the sensor
    raw = DFLEXvalRaw(DFLEX);

    // Get the normalised value from the sensor
    nrm = DFLEXvalNorm(DFLEX);

    displayTextLine(2, "Raw:  %4d", raw);
    displayTextLine(4, "Norm: %4d", nrm);
    sleep(50);
  }
}
task main() {
  // The data to be written: 0x3F = 111111 binary,
  // makes all digital ports outputs.
  HTPBsetupIO(HTPB, 0x3F);

  while(true) {
    // Switch off LED on port B0
    HTPBwriteIO(HTPB, 0x00);
    sleep(30);
    wolight = HTPBreadADC(HTPB, 0, 10);

    // Switch on LED on port B0
    HTPBwriteIO(HTPB, 0x01);
    sleep(30);
    wlight = HTPBreadADC(HTPB, 0, 10);

    // Calculate the difference
    lightdelta = wlight - wolight;

    eraseDisplay();
    displayTextLine(1, "%4d", wlight);
    displayTextLine(2, "%4d", wolight);
    displayTextLine(3, "%4d", lightdelta);
    sleep(30);
  }
}
task main () {

  // declare and initialise the sensor
  tTIR tir;
  initSensor(&tir, S1);

  displayCenteredTextLine(0, "Dexter Industries");
  displayCenteredTextLine(1, "Thermal Infrared");
  displayCenteredTextLine(3, "Test 1");
  displayCenteredTextLine(5, "Connect sensor");
  displayCenteredTextLine(6, "to S1");
  sleep(2000);

  eraseDisplay();

  // set emissivity for light skin
  setEmissivity(&tir, TIR_EM_SKIN_LIGHT);

  sleep(200);

  displayCenteredTextLine(0, "Dexter Industries");
  displayCenteredTextLine(1, "Thermal Infrared");
  while (true) {
    // Read the currently detected ambient and object temp from the sensor
    readSensor(&tir);

    displayTextLine(3, "A: %3.2f", tir.ambientTemp);
    displayTextLine(4, "O: %3.2f", tir.objectTemp);
    sleep(100);
  }
}
task main(){

  short heading;
  short x_val, y_val, z_val;      // axis values

  displayCenteredTextLine(0, "Mindsensors");
  displayCenteredBigTextLine(1, "IMU");
  displayCenteredTextLine(3, "Test 2");
  displayCenteredTextLine(5, "Connect sensor");
  displayCenteredTextLine(6, "to S1");
  sleep(2000);
  eraseDisplay();

  while (true){

    // Read the Compass
    heading = MSIMUreadHeading(MSIMU);

    displayTextLine(1, "%d", heading);

    // Read the tilt
    MSIMUreadTiltAxes(MSIMU, x_val, y_val, z_val);

    displayTextLine(5, "%d", x_val);
    displayTextLine(6, "%d", y_val);
    displayTextLine(7, "%d", z_val);
    sleep(50);
  }
}
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);
		}
	}

}
task main () {

  short keys = 0;
  unsigned byte key[] = {0};
  short number = 0;
  string output;

  displayCenteredTextLine(0, "Mindsensors");
  displayCenteredBigTextLine(1, "NumPad");
  displayCenteredTextLine(3, "Test 1");
  displayCenteredTextLine(5, "Connect sensor");
  displayCenteredTextLine(6, "to S1");
  sleep(2000);

  eraseDisplay();
  displayCenteredTextLine(0, "Mindsensors NP");
  displayTextLine(1, "-------------------");
  displayTextLine(5, "-------------------");
  displayTextLine(7, "X: no key");
  while (true) {
    // Which key is being pressed now?
    if (!MSNPscanKeys(MSNP, keys, key[0], number))
      stopAllTasks();

    // "convert" to string so we can print it
    output = key;

    displayTextLine(3, "Numpad Key: %s", output);
    displayTextLine(4, "Numpad Num: %d", number);

    sleep(100);
  }
}
Esempio n. 10
0
void createTeleopConfigFile(string &sExecutableName)
{
	TFileIOResult nIoResult;
	TFileHandle hFileHandle;
	short nFileSize;

  deleteTeleOpConfigFile(); // Erase existing file

  // Create the file

  nFileSize = strlen(sExecutableName) + 4;
  OpenWrite(hFileHandle, nIoResult, sTextFileName, nFileSize);
  WriteText(hFileHandle, nIoResult, sExecutableName);
  WriteText(hFileHandle, nIoResult, ".rxe");
  Close(hFileHandle, nIoResult);

  // Display Message

  displayTextLine(5, "");

  if(nIoResult == ioRsltSuccess)
  	displayCenteredTextLine(6, "File Created" );
  else
   displayCenteredTextLine(6, "File Error");

  displayTextLine(7, "");
  wait1Msec(1250);
  return;
}
void printLayar(long red, long green, long blue){
		writeDebugStreamLine("R : %ld",red);
		writeDebugStreamLine("G : %ld",green);
		writeDebugStreamLine("B : %ld",blue);
		getColorRGB(colorSensor,red,green,blue);
		displayTextLine(2,"R : %ld",red);
		displayTextLine(3,"G : %ld",green);
		displayTextLine(4,"B : %ld",blue);
}
task main()
{
  //Create and configure struct for the compass:
   // Create struct to hold sensor data:
   tHTMC compass;
   // Initialise and configure struct and port:
   initSensor(&compass, S4);

  //Define destination coordinates:
  long destLat = 0;		// Add the latitude destination here.
  long destLong = 0;	// Add the longitude destination here.

  long GPSrelHeading;
  long distance;

  DGPSsetDestination(DGPS, destLat, destLong);

  while (DGPSreadDistToDestination(DGPS) > 0) //Travelling to destination
  		{
        GPSrelHeading = DGPSreadRelHeading(DGPS);
        distance = DGPSreadDistToDestination(DGPS);

  		  // Here, the relative heading of the GPS is set as the target heading of the compass;
        // a compass.relativeHeading of 0 means the destination is straight ahead, > 0 heading means it
        // is to the left, and < 0 means the dest is to the right.
        readSensor(&compass);
        compass.offset = GPSrelHeading;

        displayTextLine(3, "GPSRelHead: %d", GPSrelHeading);
    		readSensor(&compass);
		    displayTextLine(5, "CompRelHead: %d", compass.relativeHeading);
  		  displayTextLine(7, "Distance: %d", distance);

  		  setMotorSpeed(LEFT, 75);
  			setMotorSpeed(RIGHT, 75);

  			readSensor(&compass);
  		  if (compass.relativeHeading > 5) //If car is right of dest., turn left
  			     {
  				     steerLeft();
  			     }
  			     else if (compass.relativeHeading < -5) //If car is left of dest., turn right
  			          {
  			            steerRight();
  			          }
  			          else //dest. is forward
  			          {
  			            steerRecenter();
  			          }
  		  sleep(1000);
  	  }
  		//Destination reached
  		setMotorSpeed(LEFT, 0);
  		setMotorSpeed(RIGHT, 0);
  		steerRecenter();
}
task main()
{
	long red,green,blue;
	float jarakSementara = 0;
	// sensor sees light:
	resetTimer(timer1);
	int costWarna;
  while(true)
  {
		printLayar(red,green,blue);
		getColorRGB(colorSensor,red,green,blue);
		if(red < 20 && green < 20 && blue < 20)
    {
      // counter-steer left:
      motor[leftMotor]  = 25;
      motor[rightMotor] = 15;
    }
    // sensor sees dark:
    else if (red > 70 && green > 70 && blue > 70)
    {
    	//counter right
    	motor[leftMotor]  = 5;
      motor[rightMotor] = 25;
    }
    //sensor sees light
    else
    {
    	//go straight
      motor[leftMotor]  = 20;
      motor[rightMotor] = 20;
      sleep(200);
    	costWarna = checkCost(red,green,blue);
    	if (costWarna == 100) //intersection green
    	{
    		motor[leftMotor]  = 0;
      	motor[rightMotor] = 0;
      	sleep(1000);
      	displayTextLine(7,"detected intersection");
      } else if (costWarna == 101) //intersection green
    	{
    		turnLeft();
    		turnLeft();
      	sleep(1000);
      	displayTextLine(7,"detected stop turn around");
      }
      displayTextLine(6,"costWarna = %d",costWarna);


    }

    jarakSementara = getTimer(timer1, seconds);

    printJarak(jarakSementara);
  }
}
task main () {
  short soundraw = 0;
  short soundnorm = 0;
  bool dba = false;

  nNxtButtonTask  = -2;

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

  eraseDisplay();
  displayTextLine(0, "Lego Sound Sensor");
  displayTextLine(6, "[enter] to switch");
  displayTextLine(7, "dB and dBA mode");

  // Set the sensor to dB mode.
  SNDsetDB(LEGOSND);
  displayCenteredTextLine(1, "dB mode");

  while(true) {
    // The enter button has been pressed, switch
    // to the other mode
    if (nNxtButtonPressed == kEnterButton) {
      dba = !dba;
      if (!dba) {
        // set the sensor to DB mode
        SNDsetDB(LEGOSND);
        displayCenteredTextLine(1, "dB mode");
      } else {
        // set the sensor to dBA mode.
        SNDsetDBA(LEGOSND);
        displayCenteredTextLine(1, "dBA mode");
      }

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

    // Read the normalised value of the sensor
    soundraw = SNDreadRaw(LEGOSND);

    // Display the raw and normalised values
    soundnorm = SNDreadNorm(LEGOSND);

    // display the info from the sensor
    displayTextLine(3, "Raw:  %3d", soundraw);
    displayTextLine(4, "Norm: %3d", soundnorm);
    sleep(50);
  }
}
 /*
  =============================================================================
  main task with some testing code

 */
task main() {
  // Standard range is set to short range
  bool shortrange = true;
  tObstacleZone zone = MSSUMO_NONE;
  nNxtButtonTask  = -2;

  eraseDisplay();

  displayCenteredTextLine(0, "Mindsensors");
  displayCenteredBigTextLine(1, "SUMO Eyes");
  displayCenteredTextLine(3, "Test 1");
  displayCenteredTextLine(5, "Press enter to");
  displayCenteredTextLine(6, "switch between");
  displayCenteredTextLine(7, "ranges");
  sleep(2000);
  eraseDisplay();

  // Set the sensor to short range
  MSSUMOsetShortRange(HTMSSUMO);

  while(true) {
    if (time1[T1] > 1000) {
      if (shortrange == false) {
        // set the sensor to short range and display this
        MSSUMOsetShortRange(HTMSSUMO);
        displayClearTextLine(1);
        displayTextLine(1, "Short range");
        shortrange = true;
      } else {
        // set the sensor to long range and display this
        MSSUMOsetLongRange(HTMSSUMO);
        displayClearTextLine(1);
        displayTextLine(1, "Long range");
        shortrange = false;
      }
      playSound(soundBeepBeep);
      while(bSoundActive)
      time1[T1] = 0;
    }

    while(nNxtButtonPressed != kEnterButton) {
      // Read the zone data
      zone = MSSUMOreadZone(HTMSSUMO);

      switch (zone) {
        case MSSUMO_FRONT: displayCenteredBigTextLine(4, "FRONT"); break;
        case MSSUMO_LEFT:  displayCenteredBigTextLine(4, "LEFT");  break;
        case MSSUMO_RIGHT: displayCenteredBigTextLine(4, "RIGHT"); break;
        case MSSUMO_NONE:  displayCenteredBigTextLine(4, "NONE");  break;
      }
      sleep(50);
    }
  }
}
// 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");
    }
  }
}
task main () {
  short distance = 0;
  short voltage = 0;
  short mindist = 0;
  short maxdist = 0;
  string type;

  displayCenteredTextLine(0, "Mindsensors");
  displayCenteredBigTextLine(1, "DIST-nx");
  displayCenteredTextLine(3, "Test 1");

  sleep(2000);

  playSound(soundBeepBeep);
  while(bSoundActive) EndTimeSlice();
  eraseDisplay();

  // Read the minimum distance the sensor can "see"
  mindist = MSDISTreadMinDist(MSDIST);

  // Read the maximum distance the sensor can "see"
  maxdist = MSDISTreadMaxDist(MSDIST);

  // Get the type of Sharp IR module connected to the sensor
  switch(MSDISTreadModuleType(MSDIST)) {
    case MSDIST_GP2D12:  type = " GP2D12"; break;
    case MSDIST_GP2D120: type = "GP2D120"; break;
    case MSDIST_GP2YA02: type = "GP2YA02"; break;
    case MSDIST_GP2YA21: type = "GP2YA21"; break;
    case MSDIST_CUSTOM:  type = " CUSTOM"; break;
  }

  displayTextLine(5, "Type: %s", type);
  displayTextLine(6, "Min:   %4dmm", mindist);
  displayTextLine(7, "Max:   %4dmm", maxdist);

  while (true) {
    // Get the distance calculated based on the data from the IR Sharp module
    distance = MSDISTreadDist(MSDIST);

    // Get the raw voltage data from the Sharp IR module
    voltage = MSDISTreadVoltage(MSDIST);
    if (distance < 0) {
      displayTextLine(4, "ERROR!!");
      sleep(2000);
      stopAllTasks();
    }

    displayCenteredBigTextLine(0, "%4dmm", distance);
    displayCenteredBigTextLine(3, "%4dmV", voltage);
    sleep(50);
  }
}
task main () {
  long encA  = 0;
  long encB  = 0;

  long distance = 0;
  long mindist = 0;
  long maxdist = 0;

  short motorSpeed = 0;

  eraseDisplay();
  MSMMUXinit();

  MSMotorStop(mmotor_S1_1);
  MSMotorStop(mmotor_S1_2);

  sleep(500);

  // Reset the encoders.  This can be done individually or all at once.
  // You should do this at the start of your program.
  MSMMotorEncoderResetAll(MSMMUX);

  // Read the minimum distance the sensor can "see"
  mindist = MSDISTreadMinDist(MSDIST);

  // Read the maximum distance the sensor can "see"
  maxdist = MSDISTreadMaxDist(MSDIST);

  while (true) {
    distance = MSDISTreadDist(MSDIST);

    // Retrieve the motor-MUX's encoder counts
    encA = MSMMotorEncoder(mmotor_S1_1);
    encB = MSMMotorEncoder(mmotor_S1_2);

    // calculate the motor speed
    motorSpeed = ((distance - mindist) * 100) / (maxdist - mindist);

    // Tell the motors to start moving.
    MSMMotor(mmotor_S1_1, motorSpeed);
    MSMMotor(mmotor_S1_2, motorSpeed);

    // Display the info.
    displayTextLine(4, "D: %5d", distance);
    displayTextLine(5, "A: %5d (%3d)", encA, motorSpeed);
    displayTextLine(6, "B: %5d (%3d)", encB, motorSpeed);
    sleep(20);
  }
}
Esempio n. 19
0
int alignToLine(){
	int nowGyro = getGyroDegrees(gyroSensor);
	int deltaGyro = 0;
	int result = 1;

	while (!isSensorSeesLight() && (( nowGyro - getGyroDegrees(gyroSensor)) <= 120)) {
    	steerRightFixedAxis();
  }
  deltaGyro = nowGyro-getGyroDegrees(gyroSensor);
  displayTextLine(12,"%d",deltaGyro);

  //Kasus menemukan sudut tumpul
  if  ((deltaGyro >60) && (deltaGyro <122)) {
  		result = 2;
	}
	//Kasus tidak menemukan garis
  if ( !isSensorSeesLight()) {
  	while( nowGyro-getGyroDegrees(gyroSensor) >= 0) {
  			steerLeftFixedAxis();
  	}
  	result = 0;
	}

	return result;
}
task main() {
  // Local variables
  short soundlevel;
  ubyte outputdata;

  // The data to be written: 0x3F = 111111 binary,
  // makes all digital ports outputs.
  HTPBsetupIO(HTPB, 0x3F);

  while(true) {
    // Get the value from the LEGO sound sensor.
    soundlevel = 1023 - SensorValue[SOUND_PORT];

    eraseDisplay();
    displayTextLine(1, "%d", soundlevel);

    // Depending on the input voltage on A0,
    // turn on the corresponding LED.
    outputdata = 0x01;
    outputdata = 0x01;
    if (soundlevel >  65) outputdata = 0x02;
    if (soundlevel > 108) outputdata = 0x04;
    if (soundlevel > 180) outputdata = 0x08;
    if (soundlevel > 300) outputdata = 0x10;
    if (soundlevel > 500) outputdata = 0x20;

    HTPBwriteIO(HTPB, outputdata);
    sleep(50);
  }
}
task main () {
  nNxtButtonTask  = -2;
  displayCenteredTextLine(0, "Mindsensors");
  displayCenteredBigTextLine(1, "Angle");
  displayCenteredTextLine(3, "Test 2");
  displayCenteredTextLine(5, "Connect sensor");
  displayCenteredTextLine(6, "to S1");
  MSANGresetAngle(MSANG);
  sleep(2000);

  eraseDisplay();

  while (true) {
    // Reset the angle to 0
    if (nNxtButtonPressed == kEnterButton)
    {
      debounce();
      calibrateScales();
      debounce();
    }
    displayCenteredTextLine(0, "GlideWheel-AS");
    displayCenteredTextLine(1, "Weighing scale");
    displayTextLine(7, "[enter] to calib.");

    displayCenteredBigTextLine(4, "%d g", weighObject());

    sleep(20);
  }
}
task main () {
  short red = 0;
  short green = 0;
  short blue = 0;
  short _color = 0;
  string _tmp;

  displayCenteredTextLine(0, "HiTechnic");
  displayCenteredBigTextLine(1, "COLOUR");
  displayCenteredTextLine(3, "Test 1");
  displayCenteredTextLine(5, "Connect sensor");
  displayCenteredTextLine(6, "to S1");
  sleep(2000);

  eraseDisplay();
  while (true) {
    // Read the currently detected colour from the sensor
    _color = HTCSreadColor(HTCS);

    // If colour == -1, it implies an error has occurred
    if (_color < 0) {
      displayTextLine(4, "ERROR!!");
      sleep(2000);
      stopAllTasks();
    }

    // Read the RGB values of the currently colour from the sensor
    // A return value of false implies an error has occurred
    if (!HTCSreadRGB(HTCS, red, green, blue)) {
      displayTextLine(4, "ERROR!!");
      sleep(2000);
      stopAllTasks();
    }

    displayCenteredTextLine(0, "Color: %d", _color);
    displayCenteredBigTextLine(1, "R  G  B");

    eraseRect(0,10, 99, 41);
    fillRect( 0, 10, 30, 10 + (red+1)/8);
    fillRect(35, 10, 65, 10 + (green+1)/8);
    fillRect(70, 10, 99, 10 + (blue+1)/8);
    StringFormat(_tmp, " %3d   %3d", red, green);
    displayTextLine(7, "%s   %3d", _tmp, blue);

    sleep(100);
  }
}
Esempio n. 23
0
void driveToTarget(int target) {
    displayTextLine(1, "%d", target);
    resetMotorEncoder(LWheel);
    resetMotorEncoder(RWheel);
    setMotorSpeed(RWheel, 15);
    setMotorSpeed(LWheel, 15);
    while (getMotorEncoder(LWheel) < target || getMotorEncoder(RWheel) < target) {}
}
Esempio n. 24
0
//displays the array and writes to a file
void checkarray(void)
{
	string line1='\n';
	int line2=strlen(line1);

	displayTextLine(2,"%c,%c,%c,%c,%c,%c,%c,%c,%c",grid[6][0],grid[6][1],grid[6][2],grid[6][3],grid[6][4],grid[6][5],grid[6][6],grid[6][7],grid[6][8]);
	displayTextLine(3,"%c,%c,%c,%c,%c,%c,%c,%c,%c",grid[5][0],grid[5][1],grid[5][2],grid[5][3],grid[5][4],grid[5][5],grid[5][6],grid[5][7],grid[5][8]);
	displayTextLine(4,"%c,%c,%c,%c,%c,%c,%c,%c,%c",grid[4][0],grid[4][1],grid[4][2],grid[4][3],grid[4][4],grid[4][5],grid[4][6],grid[4][7],grid[4][8]);
	displayTextLine(5,"%c,%c,%c,%c,%c,%c,%c,%c,%c",grid[3][0],grid[3][1],grid[3][2],grid[3][3],grid[3][4],grid[3][5],grid[3][6],grid[3][7],grid[3][8]);
	displayTextLine(6,"%c,%c,%c,%c,%c,%c,%c,%c,%c",grid[2][0],grid[2][1],grid[2][2],grid[2][3],grid[2][4],grid[2][5],grid[2][6],grid[2][7],grid[2][8]);
	displayTextLine(7,"%c,%c,%c,%c,%c,%c,%c,%c,%c",grid[1][0],grid[1][1],grid[1][2],grid[1][3],grid[1][4],grid[1][5],grid[1][6],grid[1][7],grid[1][8]);
	displayTextLine(8,"%c,%c,%c,%c,%c,%c,%c,%c,%c",grid[0][0],grid[0][1],grid[0][2],grid[0][3],grid[0][4],grid[0][5],grid[0][6],grid[0][7],grid[0][8]);
	motor[motorB]=0;
	motor[motorC]=0;
	wait1Msec(1000);

	//write to file
	for(int h=0;h<7;h++)
	{
		for(int j=0;j<9;j++)
		{
				fileWriteChar(fileHandle,grid[h][j]);
		}
		fileWriteData(fileHandle,line1,line2);
	}
	fileClose(fileHandle);
}//end check array()
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);
  }
}
Esempio n. 26
0
void cekHue(){
	int hue;
	motor[leftMotor] = 0;
	motor[rightMotor] = 0;
	while(1) {
  	displayTextLine(1,"Hue : %d",hue);
		hue=getColorHue(colorSensor);
	}
}
Esempio n. 27
0
task main()
{
	while (true)
	{
		gyro_value = SensorValue(GyroSensor) - offset;
		displayTextLine(1, "Gyro reading: %d", gyro_value);
    //wait1Msec(2);
	}
}
Esempio n. 28
0
task main() {
  // The data to be written: 0x10 = 010000 binary,
  // makes B4 digital port an output.
  HTSPBsetupIO(HTSPB, 0x10);

  while(true) {
    if(HTSPBreadIO(HTSPB, 0x01) == 0) {
      eraseDisplay();
      displayTextLine(1, "Magnet present");
      HTSPBwriteIO(HTSPB, 0x10);
    } else {
      eraseDisplay();
      displayTextLine(1, "Magnet absent");
      HTSPBwriteIO(HTSPB, 0x00);
    }
    wait1Msec(50);
  }
}
Esempio n. 29
0
task main()
{
    eraseDisplay();

    if (HTSMUXreadSensorType(IRL) == HTSMUXIRSeeker) {
        writeDebugStreamLine("IRL is HTSMUXIRSeeker");
    }
    else if (HTSMUXreadSensorType(IRL) == HTSMUXIRSeekerNew ) {
        writeDebugStreamLine("IRL is HTSMUXIRSeekerNew");
    }
    else {
        writeDebugStreamLine("IRL is unknown");
    }

    if (HTSMUXreadSensorType(IRR) == HTSMUXIRSeeker) {
        writeDebugStreamLine("IRR is HTSMUXIRSeeker");
    }
    else if (HTSMUXreadSensorType(IRR) == HTSMUXIRSeekerNew ) {
        writeDebugStreamLine("IRR is HTSMUXIRSeekerNew");
    }
    else {
        writeDebugStreamLine("IRR is unknown");
    }

    while(true)
    {
        eraseDisplay();

        byte status = HTSMUXreadStatus(S1);
        displayTextLine(1, "Status: %d", status);
        if(status & HTSMUX_STAT_BATT ==	HTSMUX_STAT_BATT) {
            displayTextLine (1, "no power to MUX");
            PlaySound(soundException);
            // PlaySound(soundBeepBeep);
        }

        int currentIRL = HTIRS2readACDir(IRL);
        int currentIRR = HTIRS2readACDir(IRR);

        int irl1, irl2, irl3, irl4, irl5 = -1;
        int irr1, irr2, irr3, irr4, irr5 = -1;
        HTIRS2readAllACStrength(IRL, irl1, irl2, irl3, irl4, irl5 );
        HTIRS2readAllACStrength(IRR, irr1, irr2, irr3, irr4, irr5 );

        displayTextLine(2, "D %d %d", currentIRL, currentIRR);
        displayTextLine(3, "0 %d %d", irl1, irr1);
        displayTextLine(4, "1 %d %d", irl2, irr2);
        displayTextLine(5, "2 %d %d", irl3, irr3);
        displayTextLine(6, "3 %d %d", irl4, irr4);
        displayTextLine(7, "4 %d %d", irl5, irr5);
    }
}
task main () {
  float x_Phi = 0.0;   // should be 0.494233933 according to Excel
  float X_val = -20;
  float X_mean = -19.80093313;   // mu
  float X_std = 13.77254704;     // sigma

  x_Phi = Phi(X_val, X_mean, X_std);

  displayTextLine(2, "Phi(x): %f", x_Phi);
  while(nNxtButtonPressed != kEnterButton) EndTimeSlice();
}