|
rohan28
Rookie
Joined: Mon Dec 12, 2011 2:10 am Posts: 10
|
 Help! how to declare color blue as a endPoint Task?..
I use three color. Yellow, Green, Blue. Yellow and Green are objective item in the field Blue is a endPoint how to locate the data files from NXT memory and send to cellphone via bluetooth
#pragma config(Sensor, S1, colorPort, sensorCOLORFULL) #pragma config(Sensor, S2, compassSensor, sensorVirtualCompass) #pragma config(Sensor, S3, lightSensor, sensorLightActive) #pragma config(Sensor, S4, sonarSensor, sensorSONAR) #pragma config(Motor, motorA, gripperMotor, tmotorNormal, PIDControl, encoder) #pragma config(Motor, motorB, rightMotor, tmotorNormal, PIDControl, encoder) #pragma config(Motor, motorC, leftMotor, tmotorNormal, PIDControl, encoder)
void displayRGBColorValues(); void displaySingleColorValue(); void displayPegCounts(); task buttonTask(); bool bDisplayPegCounts = false; int msgSize; byte msg[58];
task main() { nxtDisplayCenteredBigTextLine(0, "Color"); nxtDisplayCenteredBigTextLine(2, "Sensor"); nxtDisplayCenteredBigTextLine(4, "Test");
StartTask(buttonTask);
wait1Msec(200);
nVolume = 2; while (true) { bool bFlashingState = true;
while (true) { if (validColorSensor(colorPort)) break; if (bFlashingState) { nxtDisplayCenteredTextLine(6, "Connect Sensor"); nxtDisplayCenteredTextLine(7, "to Port S1"); PlaySound(soundBeepBeep); } else { nxtDisplayCenteredTextLine(6, ""); nxtDisplayCenteredTextLine(7, ""); } bFlashingState = !bFlashingState; wait1Msec(300); } PlaySound(soundFastUpwardTones); eraseDisplay(); while (true) { if (!validColorSensor(colorPort)) break;
if (bDisplayPegCounts) { displayPegCounts(); } else { nxtDisplayTextLine(2, ""); switch (SensorType[colorPort]) { case sensorCOLORNONE: nxtDisplayCenteredBigTextLine(0, "Ambient"); displaySingleColorValue(); break; case sensorCOLORRED: nxtDisplayCenteredBigTextLine(0, "Red"); displaySingleColorValue(); break; case sensorCOLORGREEN: nxtDisplayCenteredBigTextLine(0, "Green"); displaySingleColorValue(); break; case sensorCOLORBLUE: nxtDisplayCenteredBigTextLine(0, "Blue"); displaySingleColorValue(); break; case sensorCOLORFULL: nxtDisplayCenteredBigTextLine(0, "RGB"); displayRGBColorValues(); break; default: nxtDisplayCenteredBigTextLine(0, "Bad Type"); break; } } wait1Msec(150); } } }
task buttonTask() { while (true) { wait1Msec(100); if (!validColorSensor(colorPort)) continue;
switch (nNxtButtonPressed) { case kExitButton: StopAllTasks(); break;
case kEnterButton: hogCPU(); eraseDisplay(); bDisplayPegCounts = !bDisplayPegCounts; releaseCPU(); while (nNxtButtonPressed != kNoButton) {} break;
case kRightButton: switch (SensorType[colorPort]) { case sensorCOLORNONE: SensorType[colorPort] = sensorCOLORRED; break; case sensorCOLORRED: SensorType[colorPort] = sensorCOLORGREEN; break; case sensorCOLORGREEN: SensorType[colorPort] = sensorCOLORBLUE; break; case sensorCOLORBLUE: SensorType[colorPort] = sensorCOLORFULL; break; default: case sensorCOLORFULL: SensorType[colorPort] = sensorCOLORNONE; break; } while (nNxtButtonPressed != kNoButton) {} break;
case kLeftButton: switch (SensorType[colorPort]) { case sensorCOLORNONE: SensorType[colorPort] = sensorCOLORFULL; break; case sensorCOLORRED: SensorType[colorPort] = sensorCOLORNONE; break; case sensorCOLORGREEN: SensorType[colorPort] = sensorCOLORRED; break; case sensorCOLORBLUE: SensorType[colorPort] = sensorCOLORGREEN; break; default: case sensorCOLORFULL: SensorType[colorPort] = sensorCOLORBLUE; break; } while (nNxtButtonPressed != kNoButton) {} break; } } }
void displayColorIndex() { string sColor;
switch (SensorValue[colorPort]) { case BLACKCOLOR: sColor = "Black"; break; case BLUECOLOR: sColor = "Blue"; break; case GREENCOLOR: sColor = "Green"; break; case YELLOWCOLOR: sColor = "Yellow"; break; case REDCOLOR: sColor = "Red"; break; case WHITECOLOR: sColor = "White"; break; default: sColor = "???"; break; } nxtDisplayCenteredTextLine(2, sColor); }
void displayRGBColorValues() { short nAtoDValues[4]; short nRawValues[4]; short nColorValues[4]; string sTemp;
getColorSensorData(colorPort, colorAtoD, &nAtoDValues); getColorSensorData(colorPort, colorRaw, &nRawValues); getColorSensorData(colorPort, colorValue, &nColorValues);
displayColorIndex();
nxtDisplayTextLine(3, " AtoD Raw %%"); StringFormat(sTemp, "R %4i%5i", nAtoDValues[0], nRawValues[0]); nxtDisplayTextLine(4, "%s%4i", sTemp, nColorValues[0]); StringFormat(sTemp, "G %4i%5i", nAtoDValues[1], nRawValues[1]); nxtDisplayTextLine(5, "%s%4i", sTemp, nColorValues[1]); StringFormat(sTemp, "B %4i%5i", nAtoDValues[2], nRawValues[2]); nxtDisplayTextLine(6, "%s%4i", sTemp, nColorValues[2]); StringFormat(sTemp, "Amb%4i%5i", nAtoDValues[3], nRawValues[3]); nxtDisplayTextLine(7, "%s%4i", sTemp, nColorValues[3]); }
void displaySingleColorValue() { word nAtoDValue; word nRawValue; word nColorValue; string sTemp;
nAtoDValue = 0; nRawValue = SensorRaw[colorPort]; nColorValue = SensorValue[colorPort];
nxtDisplayTextLine(3, " AtoD Raw %%"); switch (SensorType[colorPort]) { case sensorCOLORRED: StringFormat(sTemp, "R %4i%5i", nAtoDValue, nRawValue); nxtDisplayTextLine(4, "%s%4i", sTemp, nColorValue); break; case sensorCOLORGREEN: StringFormat(sTemp, "G %4i%5i", nAtoDValue, nRawValue); nxtDisplayTextLine(5, "%s%4i", sTemp, nColorValue); break; case sensorCOLORBLUE: StringFormat(sTemp, "B %4i%5i", nAtoDValue, nRawValue); nxtDisplayTextLine(6, "%s%4i", sTemp, nColorValue); break; case sensorCOLORNONE: StringFormat(sTemp, "Amb%4i%5i", nAtoDValue, nRawValue); nxtDisplayTextLine(7, "%s%4i", sTemp, nColorValue); break; } }
void displayPegCounts() {
TColorPegCounts nPegCounts;
getColorSensorPegCounts(colorPort, &nPegCounts);
nxtDisplayCenteredBigTextLine(0, "PegCounts");
nxtDisplayTextLine(2, "%5d Reads", nPegCounts.nReadCount); nxtDisplayTextLine(3, ""); nxtDisplayTextLine(4, "%5d Disconnect", nPegCounts.nDisconnects); nxtDisplayTextLine(5, "%5d Soft Reset", nPegCounts.nSoftwareResets); nxtDisplayTextLine(6, "%5d CRC Errs:", nPegCounts.nCRCMismatch); nxtDisplayTextLine(7, "%5d Wait 4 H/W", nPegCounts.nWaitForConnect); nxtDisplayTextLine(1, "%3d, %3d",cCmdBTCheckStatus(0)); // check for a BT connection switch (cCmdBTCheckStatus(0)) { case(ioRsltSuccess): // connected; nxtDisplayTextLine(2," Connected"); // check for msg in mailbox1; msgSize=cCmdMessageGetSize(mailbox1); if (msgSize>0) { cCmdMessageRead(msg, msgSize, mailbox1); nxtDisplayTextLine(3, msg); } break; case(ioRsltCommChannelNotReady): // not connected; nxtDisplayTextLine(2,"Disconnected"); break; default: // Other condition; nxtDisplayTextLine(2, "%3d, %3d",cCmdBTCheckStatus(0)); break; } wait1Msec(10); }
tnx for helping me!! where i put the endTask using color blue
|