#pragma config(Sensor, S1, HTMAG, sensorAnalogInactive)
#include "drivers/hitechnic-magfield.h"
task main () {
int magFieldValue = 0;
int calibrationValue = 0;
nxtDisplayCenteredTextLine(0, "HiTechnic");
nxtDisplayCenteredBigTextLine(1, "MAGNETIC");
nxtDisplayCenteredTextLine(3, "Field Sensor");
nxtDisplayCenteredTextLine(4, "Test 1");
nxtDisplayCenteredTextLine(5, "Connect Sensor");
nxtDisplayCenteredTextLine(6, "to S1");
wait1Msec(2000);
nxtDisplayCenteredTextLine(5, "Press enter");
nxtDisplayCenteredTextLine(6, "to set bias");
wait1Msec(2000);
eraseDisplay();
while(true) {
eraseDisplay();
nxtDisplayTextLine(1, "Resetting");
nxtDisplayTextLine(2, "bias");
wait1Msec(500);
calibrationValue = HTMAGstartCal(HTMAG);
nxtDisplayTextLine(2, "Bias: %4d", calibrationValue);
PlaySound(soundBlip);
while(bSoundActive) EndTimeSlice();
while(nNxtButtonPressed != kNoButton) EndTimeSlice();
while(nNxtButtonPressed != kEnterButton) {
eraseDisplay();
calibrationValue = HTMAGreadCal(HTMAG);
magFieldValue = HTMAGreadVal(HTMAG);
nxtDisplayTextLine(1, "Reading");
nxtDisplayTextLine(2, "Bias: %4d", calibrationValue);
nxtDisplayClearTextLine(4);
nxtDisplayTextLine(4, "Mag: %4d", magFieldValue);
nxtDisplayTextLine(6, "Press enter");
nxtDisplayTextLine(7, "to recalibrate");
wait1Msec(100);
}
}
}