task main () { int _x_accel = 0; int _y_accel = 0; int _z_accel = 0; int _x_tilt = 0; int _y_tilt = 0; int _z_tilt = 0; string _tmp; nxtDisplayCenteredTextLine(0, "Mindsensors"); nxtDisplayCenteredBigTextLine(1, "ACCEL-Nx"); nxtDisplayCenteredTextLine(3, "Test 1"); wait1Msec(2000); // There are four ranges the ACCL-Nx can measure in // up to 2.5G - MSAC_RANGE_2_5 // up to 3.3G - MSAC_RANGE_3_3 // up to 6.7G - MSAC_RANGE_6_7 // up to 10G - MSAC_RANGE_10 MSACsetRange(MSAC, MSAC_RANGE_10); PlaySound(soundBeepBeep); while(bSoundActive); while (true) { eraseDisplay(); // Read the tilt data from the sensor if (!MSACreadTilt(MSAC, _x_tilt, _y_tilt, _z_tilt)) { nxtDisplayTextLine(4, "ERROR!!"); wait1Msec(2000); StopAllTasks(); } // Read the acceleration data from the sensor if (!MSACreadAccel(MSAC, _x_accel, _y_accel, _z_accel)) { nxtDisplayTextLine(4, "ERROR!!"); wait1Msec(2000); StopAllTasks(); } nxtDisplayTextLine(0,"MSAC Test 1"); // We can't provide more than 2 parameters to nxtDisplayTextLine(), // so we'll do in two steps using StringFormat() nxtDisplayTextLine(2, "Tilt X Y Z"); StringFormat(_tmp, " %4d %4d", _x_tilt, _y_tilt); nxtDisplayTextLine(3, "%s %4d", _tmp, _z_tilt); nxtDisplayTextLine(4, "Acceleration:"); nxtDisplayTextLine(5, "X: %5d mG", _x_accel); nxtDisplayTextLine(6, "Y: %5d mG", _y_accel); nxtDisplayTextLine(7, "Z: %5d mG", _z_accel); wait1Msec(100); } }
task main () { int _x_tilt = 0; int _y_tilt = 0; int _z_tilt = 0; int tone1; int tone2; int waitTime; nxtDisplayCenteredTextLine(0, "Mindsensors"); nxtDisplayCenteredBigTextLine(1, "ACCEL-Nx"); nxtDisplayCenteredTextLine(3, "Test 2"); wait1Msec(2000); // There are four ranges the ACCL-Nx can measure in // up to 2.5G - MSAC_RANGE_2_5 // up to 3.3G - MSAC_RANGE_3_3 // up to 6.7G - MSAC_RANGE_6_7 // up to 10G - MSAC_RANGE_10 MSACsetRange(MSAC, MSAC_RANGE_10); PlaySound(soundBeepBeep); while(bSoundActive) EndTimeSlice(); while (true) { // Read the tilt data from the sensor if (!MSACreadTilt(MSAC, _x_tilt, _y_tilt, _z_tilt)) { nxtDisplayTextLine(4, "ERROR!!"); wait1Msec(2000); StopAllTasks(); } // Tilt values seem to go from about -20 to +20. // Adding 20 to them makes them go from 0 to 40. // Make sure the tones are at least 0Hz tone1 = max2(0, (_x_tilt + 20) * 20); tone2 = max2(0, (_z_tilt + 20) * 25); // Make sure the wait time is at least 10ms waitTime = max2(10, (_y_tilt + 20)); PlayImmediateTone(tone1, 5); wait1Msec(waitTime); PlayImmediateTone(tone2, 1); } }