#pragma config(Sensor, S1, MSDIST, sensorI2CCustomFastSkipStates9V)
#include "drivers/mindsensors-irdist.h"
task main () {
int distance = 0;
int voltage = 0;
int mindist = 0;
int maxdist = 0;
string type;
nxtDisplayCenteredTextLine(0, "Mindsensors");
nxtDisplayCenteredBigTextLine(1, "DIST-nx");
nxtDisplayCenteredTextLine(3, "Test 1");
wait1Msec(2000);
PlaySound(soundBeepBeep);
while(bSoundActive) EndTimeSlice();
eraseDisplay();
mindist = MSDISTreadMinDist(MSDIST);
maxdist = MSDISTreadMaxDist(MSDIST);
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;
}
nxtDisplayTextLine(5, "Type: %s", type);
nxtDisplayTextLine(6, "Min: %4dmm", mindist);
nxtDisplayTextLine(7, "Max: %4dmm", maxdist);
while (true) {
distance = MSDISTreadDist(MSDIST);
voltage = MSDISTreadVoltage(MSDIST);
if (distance < 0) {
nxtDisplayTextLine(4, "ERROR!!");
wait1Msec(2000);
StopAllTasks();
}
nxtDisplayCenteredBigTextLine(0, "%4dmm", distance);
nxtDisplayCenteredBigTextLine(3, "%4dmV", voltage);
wait1Msec(50);
}
}