task main() { // Setup IAmNXT = 0; MaxNXT = 2; setupHighSpeedLink(); // eraseDisplay(); bNxtLCDStatusDisplay = true; // Enable top status line display nxtDisplayTextLine(2, "IAmNXT: %d MAX: %d", IAmNXT, MaxNXT); while(true){ if( HSpeedRxDataLen != 0 ) { // rec = (int)HSpeedRxData[0]; nxtDisplayTextLine(6, "Rx: ID %d Len %d", HSpeedRxHead[0] , HSpeedRxDataLen); nxtDisplayTextLine(7, "Rx: %d " , (int)HSpeedRxData[0] ); } HSpeedSendByte( (IAmNXT+1) % MaxNXT , status); } }
task main() { eraseDisplay(); bNxtLCDStatusDisplay = true; // Enable top status line display setupHighSpeedLink(true); // // Configure the link for raw read and write. User program will have complete control over the link. // User program will be responsible for managing the half-duplex operation and must prevent collisions! // nxtHS_Mode = hsRawMode; while(true) { char ILOVEHKK[10] = {'I',' ','L','O','V','E',' ','H','K','K'}; transmitList = 'I'; count = 1; TransmitASCII(); Receive(); string receivedcharacters; StringFromChars(receivedcharacters, receiveList); nxtDisplayString(30, receivedcharacters); wait10Msec(100); eraseDisplay(); } }
//////////////////////////////////////////////////////////////////////// // Main Task //////////////////////////////////////////////////////////////////////// task main() { eraseDisplay(); bNxtLCDStatusDisplay = true; setupHighSpeedLink(); //This is the buffer that will hold the bytes to transmit. ubyte testBytes[1]; int xmitCount = 1; nMotorEncoder[motorB] = 0; // Reset the Motor Encoder of Motor B. //The test will continue until an error occurs or //the enter button on the brick is pressed. while(nNxtButtonPressed != kEnterButton) { eraseDisplay(); int motorposn = nMotorEncoder[motorB]; //This will display the the motor position. nxtDisplayTextLine(1, (string)motorposn + " XMIT"); //Set the bytes of the buffer to the next byte. testBytes[0] = motorposn; //Transmit the bytes. int retVal = TransmitBytes(testBytes, sizeof(testBytes)); //Format the byte string and display it. string tStr0; StringFormat(tStr0, "%3d", testBytes[0]); string TempStr = tStr0; nxtDisplayTextLine(2, TempStr); //Delay. Possibly, this could be used for an ACK. wait1Msec(MS_TO_DELAY); } }
task main() { // Setup string sFriendlyName; IAmNXT = 1; MaxNXT = 4; setupHighSpeedLink(); // eraseDisplay(); bNxtLCDStatusDisplay = true; // Enable top status line displayHSpeedRxData[1] while(true) { while( HSpeedRxDataLen == 0 ) wait1Msec(10); if(HSpeedRxData[0] == 1){ } if(HSpeedRxData[0] == 2){ } if(HSpeedRxData[0] == 3){ } } }
//////////////////////////////////////////////////////////////////////////////////////////////////////// // // Main Task // //////////////////////////////////////////////////////////////////////////////////////////////////////// task main() { // Setup string sFriendlyName; getFriendlyName(sFriendlyName); IAmNXT = sFriendlyName == "HRF2" ? 0 : 1; MaxNXT = 2; setupHighSpeedLink(); // eraseDisplay(); bNxtLCDStatusDisplay = true; // Enable top status line display nxtDisplayTextLine(2, "IAmNXT: %d MAX: %d", IAmNXT, MaxNXT); if ( IAmNXT == 0 ) { send(); } else { recieve(); } }
task main() { // Setup string sFriendlyName; IAmNXT = 2; MaxNXT = 3; setupHighSpeedLink(); // eraseDisplay(); bNxtLCDStatusDisplay = true; // Enable top status line displayHSpeedRxData[1] int delta = 2; // Create int 'delta' to the be Servo Change Rate. servoChangeRate[servo1] = delta; // Slow the Servo Change Rate down to only 'delta' positions per update. servoChangeRate[servo2] = delta; // Slow the Servo Change Rate down to only 'delta' positions per update. servoChangeRate[servo3] = delta; // Slow the Servo Change Rate down to only 'delta' positions per update. servoChangeRate[servo4] = delta; // Slow the Servo Change Rate down to only 'delta' positions per update. servoChangeRate[servo5] = delta; // Slow the Servo Change Rate down to only 'delta' positions per update. while(true) { while( HSpeedRxDataLen == 0 ) wait1Msec(10); if(HSpeedRxData[0] == 1){ AbsMove(2000,2000, 360); if(ServoValue[servo1] >= 191) // If servo1 is closer to 255 (than 0): { while(ServoValue[servo1] > 125) // While the ServoValue of servo1 is greater than 0: { servo[servo1] = 125; // Move servo1 to position to 0. } } if(ServoValue[servo2] < 64) // If servo1 is closer to 0 (than 255): { while(ServoValue[servo2] < 110) // While the ServoValue of servo1 is less than 255: { servo[servo2] = 110; // Move servo1 to position to 255. } } if(ServoValue[servo3] < 64) // If servo1 is closer to 0 (than 255): { while(ServoValue[servo3] < 110) // While the ServoValue of servo1 is less than 255: { servo[servo3] = 110; // Move servo1 to position to 255. } } if(ServoValue[servo4] < 64) // If servo1 is closer to 0 (than 255): { while(ServoValue[servo4] < 110) // While the ServoValue of servo1 is less than 255: { servo[servo4] = 110; // Move servo1 to position to 255. } } if(ServoValue[servo5] < 64) // If servo1 is closer to 0 (than 255): { while(ServoValue[servo5] < 110) // While the ServoValue of servo1 is less than 255: { servo[servo5] = 110; // Move servo1 to position to 255. } } } if(HSpeedRxData[0] == 2){ if(ServoValue[servo1] < 191) // If servo1 is closer to 0 (than 255): { while(ServoValue[servo1] < 255) // While the ServoValue of servo1 is less than 255: { servo[servo1] = 255; // Move servo1 to position to 255. } } if(ServoValue[servo2] >= 64) // If servo1 is closer to 255 (than 0): { while(ServoValue[servo2] > 0) // While the ServoValue of servo1 is greater than 0: { servo[servo2] = 0; // Move servo1 to position to 0. } } if(ServoValue[servo3] >= 64) // If servo1 is closer to 255 (than 0): { while(ServoValue[servo3] > 0) // While the ServoValue of servo1 is greater than 0: { servo[servo3] = 0; // Move servo1 to position to 0. } } if(ServoValue[servo4] >= 64) // If servo1 is closer to 255 (than 0): { while(ServoValue[servo4] > 0) // While the ServoValue of servo1 is greater than 0: { servo[servo4] = 0; // Move servo1 to position to 0. } } if(ServoValue[servo5] >= 64) // If servo1 is closer to 255 (than 0): { while(ServoValue[servo5] > 0) // While the ServoValue of servo1 is greater than 0: { servo[servo5] = 0; // Move servo1 to position to 0. } } AbsMove(0,0, 0); } if(HSpeedRxData[0] == 3){ AbsMove(0,0, 0); } } }