Exemplo n.º 1
0
task main () {
  int raw = 0;
  int nrm = 0;
  // Get control over the buttons
  nNxtButtonTask  = -2;

  eraseDisplay();
  nxtDisplayTextLine(0, "Dexter Industries");
  nxtDisplayCenteredBigTextLine(1, "dFlex");
  nxtDisplayCenteredTextLine(3, "Test 2");
  nxtDisplayCenteredTextLine(5, "Connect sensor");
  nxtDisplayCenteredTextLine(6, "to S1");
  wait1Msec(2000);

  eraseDisplay();
  nxtDisplayTextLine(0, "dFlex Calibration");
  nxtDisplayTextLine(2, "Left:  set min");
  nxtDisplayTextLine(3, "Right: set max");
  nxtDisplayTextLine(7, "Grey:  exit");

  while (true) {
    switch(nNxtButtonPressed) {
      // if the left button is pressed calibrate the black value for the sensor
      case kLeftButton:
                        DFLEXcalLow(DFLEX);
                        PlaySound(soundBeepBeep);
                        while(bSoundActive);
                        break;

      // if the left button is pressed calibrate the white value for the sensor
      case kRightButton:
                        DFLEXcalHigh(DFLEX);
                        PlaySound(soundBeepBeep);
                        while(bSoundActive);
                        break;
    }

    nxtDisplayClearTextLine(5);
    nxtDisplayClearTextLine(6);

    // Read the raw value of the sensor
    raw = DFLEXvalRaw(DFLEX);

    // Read the normalised value of the sensor
    nrm = DFLEXvalNorm(DFLEX);

    // Display the raw and normalised values
    nxtDisplayTextLine(5, "R: %4d N: %4d", raw, nrm);

    // Display the values for black and white
    nxtDisplayTextLine(6, "B: %4d W: %4d", dflexlow, dflexhigh);
    wait1Msec(50);
  }
}
Exemplo n.º 2
0
void showDiagnostics(nxtState *state) {
	//create label
	string displayMode = "side = ";
	string batteryLevel = "power = ";

	//store variable in a string
	string string4 = state->mode?"right":"left";
	string string5 = externalBatteryAvg;

	//concat variable with label
	strcat(displayMode, string4);
	strcat(batteryLevel, string5);

	eraseDisplay();

	//display label and value
	nxtDisplayTextLine(1, "HangLowerer");
	nxtDisplayTextLine(2, "LftBtn:dn,RtBtn:up");
	nxtDisplayTextLine(3, "Ctr:changeSides");
	nxtDisplayTextLine(4, displayMode);
	nxtDisplayTextLine(5, batteryLevel);
}
Exemplo n.º 3
0
//function to ramp down the power
void StopMtr(int mtr, int pwr)
{
  //the power of the robot can be modeled with the sine function.
  //Thus multipling with the sine of the dummy variable i will ramp down the power
  for (int i = 90 ; i < 0; i--)
  {
    pwr = pwr * sin(i);
    nxtDisplayTextLine(3, "p: %d",pwr);

    motor[mtr] = pwr;
    wait1Msec(10);
  }
}
Exemplo n.º 4
0
task main()
{
  eraseDisplay();
  nxtDisplayCenteredTextLine(2, "Acquiring...");

  while (true)
  {
    if (readSamanthaStatus())
    {
       nxtDisplayTextLine(status.nLine, "%s", status.message);
    }
  }
}
Exemplo n.º 5
0
task main() {
  int _chVal = 0;
  nxtDisplayTextLine(3, "MAX127");
  nxtDisplayTextLine(4, "Test prog");
  wait1Msec(1000);
  eraseDisplay();

  while(true) {
    eraseDisplay();
    for (int i = 0; i < 8; i++) {
      _chVal = MAX127readChan(MAX127, MAX127_I2C_ADDR, i);
      // if the return value is < 0 then an error occurred
      if (_chVal < 0) {
        nxtDisplayTextLine(4, "ERROR!!");
        wait1Msec(2000);
        StopAllTasks();
      }
      nxtDisplayTextLine(i, "CH[%d]: %d", i, _chVal);
    }
    wait1Msec(100);
  }
}
Exemplo n.º 6
0
void BalanceOnBridgeUsingGyro()
{
	  eraseDisplay();
	    nxtDisplayTextLine(1, "Resetting");
	    nxtDisplayTextLine(1, "heading");
	    wait1Msec(100);

	    // Start the calibration and display the offset
	    nxtDisplayTextLine(2, "Offset: %4d", HTGYROstartCal(HTGYRO));
	   // wait10Msec(1000);
	    PlaySound(soundBlip);
	    while(bSoundActive);

	  StartTask(CalcHeading);

	   gPwr = -50;
	   motor[RightMtr] = gPwr;
		 motor[LeftMtr] = gPwr;
	   wait1Msec(2000);
	   //while (true)
	   {
	    gPwr = -25;
	    while(true)
	    {

	        motor[RightMtr] = gPwr;
		      motor[LeftMtr] = gPwr;
		      if( (heading < 5.5) && (heading > -5.5))
		      {
		        motor[RightMtr] = 0;
		        motor[LeftMtr] = 0;
	          wait1Msec(2000);
	  	      break;
	  	    }
	 	      wait1Msec(10);

	    }
	  }
}
Exemplo n.º 7
0
int time(){
	int d = 1;
	int wait_time = 0;
	nxtDisplayTextLine(1, "L_ARROW = +time");
	nxtDisplayTextLine(2, "R_ARROW = Determine Position");
	nxtDisplayTextLine(5, "Delay Time?");
	bool select = false;
	while(!select){

		nxtDisplayCenteredTextLine(3, "%d", d);
		if(nNxtButtonPressed == 2){         //Left arrow is button 2
			wait10Msec(50);
			wait_time = 100*d;
			d++;
			select = false;
			}else if(nNxtButtonPressed == 1){    // Right arow is button 1
			wait10Msec(50);
			select = true;
		}
	}
	return wait_time;
}
void turnDeg(float deg, float power){
	if(deg > 0){
		motor[leftBack] = power;
  	motor[rightBack] = -power;
  	while(deg >= currHeading){
			wait1Msec(1);
			nxtDisplayTextLine(2, "servo: %d", ServoValue[servo1]);
  		nxtDisplayTextLine(3, "head: %3.0f", currHeading);
  		nxtDisplayTextLine(5, "diff: %3.0f", SubtractFromCurrHeading (deg));
		}
	}else{
		deg *= -1;
		motor[leftBack] = -power;
  	motor[rightBack] = power;
  	while(SubtractFromCurrHeading(360-deg) > 0){
			wait1Msec(1);
  		nxtDisplayTextLine(3, "head: %3.0f", currHeading);
 			nxtDisplayTextLine(5, "diff: %3.0f", SubtractFromCurrHeading (deg));
		}
	}
	xSet(0);
}
task main () {
  int _x_axis1 = 0;
  int _y_axis1 = 0;
  int _z_axis1 = 0;

  int _x_axis2 = 0;
  int _y_axis2 = 0;
  int _z_axis2 = 0;

  string _tmp;

  nxtDisplayCenteredTextLine(0, "HiTechnic");
  nxtDisplayCenteredBigTextLine(1, "Accel");
  nxtDisplayCenteredTextLine(3, "Test 1");
  nxtDisplayCenteredTextLine(5, "Connect sensor");
  nxtDisplayCenteredTextLine(6, "to S1");
  wait1Msec(2000);

//  PlaySound(soundBeepBeep);
//  while(bSoundActive);

  while (true) {
    eraseDisplay();

    // You can read the three axes one by one
    HTACreadX(HTAC, _x_axis1);
    HTACreadY(HTAC, _y_axis1);
    HTACreadZ(HTAC, _z_axis1);

    // It's better to read them all at once, if you want to know
    // all of them anyway.  It is a lot more efficient.
    if (!HTACreadAllAxes(HTAC, _x_axis2, _y_axis2, _z_axis2)) {
      nxtDisplayTextLine(4, "ERROR!!");
      wait1Msec(2000);
      StopAllTasks();
    }

    nxtDisplayTextLine(0,"HTAC Test 1");

    // We can't provide more than 2 parameters to nxtDisplayTextLine(),
    // so we'll do in two steps using StringFormat()
    nxtDisplayTextLine(2, "T    X    Y    Z");
    StringFormat(_tmp, "S:%4d %4d", _x_axis1, _y_axis1);
    nxtDisplayTextLine(3, "%s %4d", _tmp, _z_axis1);

    StringFormat(_tmp, "A:%4d %4d", _x_axis2, _y_axis2);
    nxtDisplayTextLine(4, "%s %4d", _tmp, _z_axis2);

    nxtDisplayTextLine(6, "S: 1 by 1");
    nxtDisplayTextLine(7, "A: All at once");

    wait1Msec(100);
  }
}
task main () {
  tMotor testMotor = motorC;

  // PlaySound(soundBeepBeep);
  // nxtDisplayBigTextLine(3, "Retract");
  // FLACtretractLA(testMotor, 100);
  // while(!isDone(testMotor)) wait1Msec(50);
  // wait1Msec(200);
  // nMotorEncoder[testMotor] = 0;
  // wait1Msec(1000);

  PlaySound(soundBeepBeep);
  eraseDisplay();
  nxtDisplayBigTextLine(1, "Extend");
  nxtDisplayTextLine(3, "ticks:  1");
  nxtDisplayTextLine(4, "speed:  50");
  FLACextendLA(testMotor, 50, 1);
  while(!isDone(testMotor)) wait1Msec(50);
  if (isStalled(testMotor))
    nxtDisplayTextLine(7, "STALLED");
  wait1Msec(1000);

  // PlaySound(soundBeepBeep);
  // eraseDisplay();
  // nxtDisplayBigTextLine(1, "Extend");
  // nxtDisplayTextLine(3, "ticks: 100");
  // nxtDisplayTextLine(4, "speed:  80");
  // FLACextendLA(testMotor, 80, 100);
  // while(!isDone(testMotor)) wait1Msec(50);
  // if (isStalled(testMotor))
    // nxtDisplayTextLine(7, "STALLED");
  // wait1Msec(1000);
  // eraseDisplay();

  // PlaySound(soundBeepBeep);
  // nxtDisplayBigTextLine(1, "Retract");
  // nxtDisplayTextLine(3, "ticks: 120");
  // nxtDisplayTextLine(4, "speed: 100");
  // FLACtretractLA(testMotor, 100, 120);
  // while(!isDone(testMotor)) wait1Msec(50);
  // if (isStalled(testMotor))
    // nxtDisplayTextLine(7, "STALLED");
  // wait1Msec(1000);

  PlaySound(soundBeepBeep);
  nxtDisplayBigTextLine(1, "Retract");
  nxtDisplayTextLine(3, "ticks:  1");
  nxtDisplayTextLine(4, "speed: 100");
  FLACtretractLA(testMotor, 100, 1);
  while(!isDone(testMotor)) wait1Msec(50);
  if (isStalled(testMotor))
    nxtDisplayTextLine(7, "STALLED");
  wait1Msec(1000);

  PlaySound(soundBeepBeep);
  eraseDisplay();
  nxtDisplayBigTextLine(1, "Done");
  wait1Msec(2000);
}
Exemplo n.º 11
0
void moveBack(){
	if(!move)
	{
		nMotorEncoder[motorB] = 0;
		move = true;
	}
	nxtDisplayTextLine(6, "%d", nMotorEncoder[motorB]);

	encoder = nMotorEncoder[motorB];

	motor[lm] = -100;
	motor[rm] = -100;
}
task updateHUD () {
  int x = 0;
  int y = 0;

  while (true) {
    nxtEraseRect(4,50, 44,10);
    nxtDisplayTextLine(2, "        H: %3d", angleI/100);
    nxtDisplayTextLine(3, "        X: %3d", x_accel/100);
    nxtDisplayTextLine(4, "        Y: %3d", y_accel/100);
    nxtDisplayTextLine(5, "        Z: %3d", z_accel/100);
    nxtDrawCircle(84, 50, 4);

    nxtDrawCircle(4, 50, 40);
    x = (cosDegrees(-1 * (angleI/100 - 90)) * 20) + 24;
    y = (sinDegrees(-1 * (angleI/100 - 90)) * 20) + 30;
    nxtDrawLine(24, 30, x, y);
    nxtEraseRect(0,0, 99, 8);
    nxtDrawRect(0,0, 99, 8);
    nxtFillRect(50,0, (float)(rotI / 150)/100.0 *50 + 50, 8);
    wait1Msec(100);
  }
}
task updateScreen()
{
	while(true)
	{
		nxtDisplayTextLine(0, "Stat: %s", connStatus);
		nxtDisplayTextLine(1, "%s",IPaddress);
		nxtDisplayTextLine(2, "-------------------");
		nxtDisplayTextLine(3, "%s", dataStrings[0]);
		nxtDisplayTextLine(4, "%s", dataStrings[1]);
		nxtDisplayTextLine(5, "%s", dataStrings[2]);
		nxtDisplayTextLine(6, "%s", dataStrings[3]);
		nxtDisplayTextLine(7, "%s", dataStrings[4]);
		wait1Msec(100);
	}
}
Exemplo n.º 14
0
void showStatus(int rotations, int power){
		nxtDisplayTextLine(1, "Power: %d", power);
		nxtDisplayTextLine(2, "rotations: %d",rotations);
		nxtDisplayTextLine(3, "encoders: %d",nMotorEncoder[leftWheel1]);
		nxtDisplayTextLine(4, "encoders: %d",nMotorEncoder[leftWheel2]);
		nxtDisplayTextLine(5, "encoders: %d",nMotorEncoder[rightWheel1]);
		nxtDisplayTextLine(6, "encoders: %d",nMotorEncoder[rightWheel2]);
}
Exemplo n.º 15
0
task main()
{
	initializeRobot();
	waitForStart();   // wait for start of tele-op phase
	int armTarget = 0;
	int armSpeed = 0;
	while (true) {

		processEvents();

		if (wiggle) {
			if (time1[T3] % 400 >= 200) {
				driveSpeedLeft=100;
				driveSpeedRight=0;
			} else {
				driveSpeedLeft=0;
				driveSpeedRight=100;
			}
		} else {
			int maxSpd = (slowMode ? SLOWMO_DRIVE_SPEED : DRIVE_SPEED);
			driveSpeedLeft =  powscl(joystick.joy1_y1, maxSpd);  //Drive as normal taking slow-mode into account
			driveSpeedRight = powscl(joystick.joy1_y2, maxSpd);
		}

		motor[LeftDrive] = driveSpeedLeft;	//Apply drive powers
		motor[RightDrive] = driveSpeedRight;

		int oldArmSpeed=armSpeed;
		armSpeed = -1*powscl(
			((armOwner==0) ? joystick.joy2_y2 : POVAsJoystickY(joystick.joy1_TopHat)),  //R2J2-Y or R1POV-Y
			ARM_SPEED);

		// Position Regulator
		if (armSpeed==0) {
			int armPower;
			if (armSpeed != oldArmSpeed) armTarget=nMotorEncoder[BlockArm]+(sgn(oldArmSpeed)*200); //Set current pos + approx error
			if (armTarget < -300) { // Only correct if above 90 degrees, roughly
				int error = armTarget - nMotorEncoder[BlockArm];
				armPower = coerce((int)(0.1*error), -20, 20);
			} else {
				armPower=0;
			}
			nxtDisplayTextLine(3, "%i", armTarget);

			motor[BlockArm] = armPower;
		} else {
			motor[BlockArm] = armSpeed;
		}
		wait1Msec(5);
	}
}
task main () {

  int pressmInHg = 0;
  float presshPa = 0.0;
  float pressPsi = 0.0;
  float tempC = 0.0;
  float tempF = 0.0;

  nxtDisplayCenteredTextLine(0, "HiTechnic");
  nxtDisplayCenteredBigTextLine(1, "BaroTemp");
  nxtDisplayCenteredTextLine(3, "Test 1");
  nxtDisplayCenteredTextLine(5, "Connect sensor");
  nxtDisplayCenteredTextLine(6, "to S1");
  wait1Msec(2000);

  //PlaySound(soundBeepBeep);
  //while(bSoundActive);

  while (true) {
    eraseDisplay();

    // Read the sensor's data
		pressmInHg = HTBMreadMInHg(HTBM);   // Pressure in 1/1000th of an inch Hg
		presshPa = HTBMreadhPa(HTBM);       // Pressure in hecto Pascal
		pressPsi = HTBMreadPsi(HTBM);       // Pressure in Pounds per square inch
		tempC = HTBMreadTemp(HTBM);         // Temp in Celcius
		tempF = HTBMreadTempF(HTBM);        // Temp in Fahrenheit

    nxtDisplayCenteredTextLine(0, "HTBM Test 1");
    nxtDisplayTextLine(2, "%5d mInHg", pressmInHg);
    nxtDisplayTextLine(3, "%5.1f hPa", presshPa);
    nxtDisplayTextLine(4, "%5.1f PSI", pressPsi);
    nxtDisplayTextLine(6, "%3.1f C / %3.1f F", tempC, tempF);
    nxtDrawLine(0, 52, 99, 52);
    nxtDrawLine(0, 20, 99, 20);
    wait1Msec(100);
  }
}
Exemplo n.º 17
0
task main () {
  int _x_axis = 0;
  int _y_axis = 0;
  int _z_axis = 0;

  string _tmp;

  nxtDisplayCenteredTextLine(0, "HiTechnic");
  nxtDisplayCenteredBigTextLine(1, "Accel");
  nxtDisplayCenteredTextLine(3, "Test 1");
  nxtDisplayCenteredTextLine(5, "Connect sensor");
  nxtDisplayCenteredTextLine(6, "to S1");
  wait1Msec(2000);

  PlaySound(soundBeepBeep);
  while(bSoundActive) EndTimeSlice();

  while (true) {
    eraseDisplay();

    // Read all of the axes at once
    if (!HTACreadAllAxes(HTAC, _x_axis, _y_axis, _z_axis)) {
      nxtDisplayTextLine(4, "ERROR!!");
      wait1Msec(2000);
      StopAllTasks();
    }

    nxtDisplayTextLine(0,"HTAC Test 1");

    // We can't provide more than 2 parameters to nxtDisplayTextLine(),
    // so we'll do in two steps using StringFormat()
    nxtDisplayTextLine(2, "   X    Y    Z");
    StringFormat(_tmp, "%4d %4d", _x_axis, _y_axis);
    nxtDisplayTextLine(3, "%s %4d", _tmp, _z_axis);

    wait1Msec(100);
  }
}
Exemplo n.º 18
0
task main() {
  // Local variables
  int inputdata;

  while(true) {
    // Read a 10bit wide analogue value from A0
    inputdata = HTPBreadADC(HTPB, 0, 10);

    eraseDisplay();
    nxtDisplayTextLine(1, "%d", inputdata);

    wait1Msec(50);
  }
}
Exemplo n.º 19
0
task main()
{
	//turnDegrees(90, 75);
	//wallAlign(ALIGN_FORWARD);
	//goTicks(inchesToTicks(-30), 100);
	initializeRobot();
	waitForStart();


	while(true)
	{
		nxtDisplayTextLine(4, "Gyr: %f", currentGryoReading());
	}
}
Exemplo n.º 20
0
void stopAll(){
	if(move){
		float rot = getCompassValue();

		float x = sinDegrees(rot) * encoder;
		float y = cosDegrees(rot) * encoder;

		nxtDisplayTextLine(0, "%d  %d %d", rot, x, y);
		nxtDisplayTextLine(1, "%d", encoder);

		totalX+=x;
		totalY+=y;

		nMotorEncoder[motorB] = 0;
		move = false;
	}

	stopBack();
	stopF();
	stopLeft();
	stopRight();
	motor[clawm] = 0;
}
task main () {
  int dist = 0;

  nxtDisplayCenteredTextLine(0, "Lego");
  nxtDisplayCenteredBigTextLine(1, "US");
  nxtDisplayCenteredTextLine(3, "SMUX Test");
  nxtDisplayCenteredTextLine(5, "Connect SMUX to");
  nxtDisplayCenteredTextLine(6, "S1 and US sensor");
  nxtDisplayCenteredTextLine(7, "to SMUX Port 1");
  wait1Msec(2000);

  eraseDisplay();
  nxtDisplayTextLine(0, "Lego US Sensor");

  while(true) {
    // Read the current distance detected.
    dist = USreadDist(LEGOUS);

    // display the info from the sensor
    nxtDisplayTextLine(3, "Dist:  %3d cm", dist);
    wait10Msec(50);
  }
}
void rotate(int direction, int powerLevel, int stopAngle)
{
	if (direction == left)
	{
		nxtDisplayTextLine(1,"Rotating Left");
		while (happy_angle > -stopAngle)
		{
			motor[MotorL] = - powerLevel;
			motor[MotorR] = powerLevel+10;
		}
	}
	else if (direction == right)
	{
		nxtDisplayTextLine(1,"Rotating Right");
		while (happy_angle < stopAngle)
		{
			motor[MotorL] = powerLevel+10;
			motor[MotorR] = - powerLevel;
		}
	}
	writeDebugStream("No longer rotating\n");
	stop_drive();
}
Exemplo n.º 23
0
void initDebug(tDHandler count, bool big = false, bool resetAfterOverflow = false)	{
	count.count = 1;
	count.big = big;
	count.resetAfterOverflow = resetAfterOverflow;

	if(count.big)	{
		count.__maxCount = 3;
	}
	else	{
		count.__maxCount = 6;
	}

	nxtDisplayTextLine(0, "FTC5818 DBG v0.5-");
}
Exemplo n.º 24
0
void junction() {
    /*
            This code stops the robot at an intersection to make sure you can chose for it to go straight left or right.
            In case the direction is already chosen it just goes to the already chosen direction
     */

    if (SensorValue[S1] < (mincolor + 10) && SensorValue[S2] < (minlight + 10)) {//the minimul light value + 10 for the correct moment to stop at a line
    		setMultipleMotors(50, motorA, motorB); //Drive the cart forward a little for 50 miliseconds. This way it ends up more straight on the line after turning
        wait1Msec(50);
        stopTask(music); //stops the music
        clearSounds(); //clears the sound buffer
        setMultipleMotors(0, motorA, motorB); //stop the robot
        wait(1);

        while (1) {
        		nxtDisplayTextLine(0, "Counter: %d %c", counter, new_matrix[counter]);
            if (new_matrix[counter] == 'L') {//if the input is "LEFT" turn left until you read the black line color and then continue your normal duty
                motor(motorA) = 0;
                motor(motorB) = 40;
                while (1) {
                    if (SensorValue[S1] < 30) {//color sensor check
                        wait1Msec(5);
                        setMultipleMotors(0, motorA, motorB);
                        counter++;
                        break;
                    }
                }
                break;
            } else if (new_matrix[counter] == 'R') {//the same only then for turning right
                motor(motorA) = 40;
                motor(motorB) = 0;
                while (1) {
                    if (SensorValue[S2] < 50) {//light sensor check
                        wait1Msec(5);
                        setMultipleMotors(0, motorA, motorB);
                        counter++;
                        break;
                    }
                }
                break;
            }                //if up just stop the loop to exit
            else if (new_matrix[counter] == 'U') {
                setMultipleMotors(50, motorA, motorB);
                wait(0.2);
                counter++;
                break;
            }
        }
    }
}
task main() {
  int inputdata;
  ubyte outputdata;
  int bit;

  // Set all digital IOs as outputs as output
  HTSPBsetupIO(HTSPB, 0xFF);

  while(true) {
    // Read a 10bit wide analogue value from A0
    inputdata = HTSPBreadADC(HTSPB, 0, 10);

    nxtDisplayTextLine(1, "A0: %d", inputdata);

    // Set the output bit based on the analogue input value
    bit = (inputdata/128);
    if (bit > 5) bit = 5;
    nxtDisplayTextLine(2, "Bit: %d", bit);
    outputdata = 1 << bit;
    HTSPBwriteIO(HTSPB, outputdata);
    wait1Msec(50);
  }
}
Exemplo n.º 26
0
// Minimize LCD screen flicker by only updating LCD when data has changed
void displayText(int nLineNumber, string cChar, int nValueDC, int nValueAC)
{
    string sTemp;
    StringFormat(sTemp, "%4d %4d", nValueDC, nValueAC);
    // Check if the new line is the same as the previous one
    // Only update screen if it's different.
    if (sTemp != sTextLines[nLineNumber])
    {
        string sTemp2;
        sTextLines[nLineNumber] = sTemp;
        StringFormat(sTemp2, "%s: %s", cChar, sTemp);
        nxtDisplayTextLine(nLineNumber, sTemp2);
    }
}
Exemplo n.º 27
0
void drawMenu(){
  //Draw menu items
	  for(int i = 0; i<=itemsOnScreenAtATime && i < numberOfMenuItems;i++){//while we are within array and screen range
	    if(i==star){
	      //construct menu text line with star
	      menu_txt="*"+opt[i+top_menu]+"";
	    }else{
	      //construct menu text line without star
	      menu_txt=" "+opt[i+top_menu]+"";
	    }
	    //display text at line
	    nxtDisplayTextLine(i,menu_txt);
	  }
}
void dualIR()
{
 //assign leftDirRead and rightDirRead to the high pin of their respective sensors
 leftDirRead = HTIRS2readDCDir(HTIRS1);
 rightDirRead = HTIRS2readDCDir(HTIRS2);

 leftDelta = leftDirRead - median;
 rightDelta = median - rightDirRead;

 delta = leftDelta - rightDelta;

 //for the left side of the robit.
 motorPowerA = -delta * scale + power;
 // for the right side of the robit.
 motorPowerB = delta * scale + power;

 if (leftDirRead == 0 || rightDirRead == 0) // failsafe
 {
   if (leftDirRead == 0 && rightDirRead == 0)
   {
     motor[motorE] = 25;
     motor[motorD] = 25;
   }
 }
 else if (delta == 0)
 {
   motor[motorE] = 100;
   motor[motorD] = 100;
 }
 else
 {
   motor[motorE] = motorPowerA;
   motor[motorD] = motorPowerB;
 }
 nxtDisplayTextLine(1, "%d", leftDirRead);
 nxtDisplayTextLine(2, "%d", rightDirRead);
}
Exemplo n.º 29
0
task main()
{
  nNxtButtonTask  = -2;
  nxtDisplayCenteredTextLine(0, "Codatex");
  nxtDisplayCenteredBigTextLine(1, "RFID");
  nxtDisplayCenteredTextLine(3, "Test 2");
  nxtDisplayCenteredTextLine(5, "Connect sensor");
  nxtDisplayCenteredTextLine(6, "to S1");
  wait1Msec(2000);

  eraseDisplay();
  nxtDisplayCenteredTextLine(3, "Start single");
  nxtDisplayCenteredTextLine(4, "reading loop");
  wait1Msec(2000);
  eraseDisplay();

  // Set up the sensor for continuous readings.
  CTRFIDsetContinuous(CTRFID);

  // loop for transponder readings with continuous read function
  while(nNxtButtonPressed == kNoButton) {
    // read the transponder
    if (!CTRFIDreadTransponder(CTRFID, transponderID)) {
      eraseDisplay();
      nxtDisplayTextLine(3, "Error reading");
      nxtDisplayTextLine(4, "from sensor!");
      wait10Msec(5000);
      StopAllTasks();
    }
    nxtDisplayCenteredTextLine(3, "Transponder ID:");
    nxtDisplayCenteredTextLine(4, "%s", transponderID);

    // Be sure to add about 200ms after each read
    // or you end up getting 0000000000 as a transponder address
    wait1Msec(200);
  }
}
task main () {
  int _dir = 0;
	int dcS1, dcS2, dcS3, dcS4, dcS5 = 0;

  nxtDisplayCenteredTextLine(0, "HiTechnic");
  nxtDisplayCenteredBigTextLine(1, "IR Seekr");
  nxtDisplayCenteredTextLine(3, "Test 1");
  nxtDisplayCenteredTextLine(5, "This is for the");
  nxtDisplayCenteredTextLine(6, "v1 seeker");
  wait1Msec(2000);

  while(true) {
    eraseDisplay();

    // read all of the sensors' values at once,
    // exit the app if an error occurs
    if (! HTIRSreadAllStrength(HTIRS, dcS1, dcS2, dcS3, dcS4, dcS5)) {
      nxtDisplayTextLine(4, "ERROR!!");
      wait1Msec(2000);
      StopAllTasks();
    }

    // read the direction from which the signal is coming,
    // exit the app if an error occurs
    _dir = HTIRSreadDir(HTIRS);
    if (_dir < 0) {
      nxtDisplayTextLine(4, "ERROR!!");
      wait1Msec(2000);
      StopAllTasks();
    }

    // display the info from the sensor
    nxtDisplayTextLine(0,"HT IR Seeker");
    nxtDisplayTextLine(2, "dir: %2d", _dir);
    nxtDisplayTextLine(3, "S1: %3d", dcS1);
    nxtDisplayTextLine(4, "S2: %3d", dcS2);
    nxtDisplayTextLine(5, "S3: %3d", dcS3);
    nxtDisplayTextLine(6, "S4: %3d", dcS4);
    nxtDisplayTextLine(7, "S5: %3d", dcS5);
    wait10Msec(100);
  }
}