#pragma config(Sensor, S1, HTPIR, sensorI2CCustom)
#include "drivers/hitechnic-pir.h"
void drawStickFigure(int offset)
{
nxtEraseRect(0, 0, 99, 50);
nxtDrawCircle(offset + 43, 40, 15);
nxtDrawLine(offset + 50,25,offset + 50,10);
nxtDrawLine(offset + 43, 22, offset + 58, 22);
nxtDrawLine(offset + 43, 0, offset + 50, 10);
nxtDrawLine(offset + 50, 10, offset + 58, 0);
}
task main () {
int reading = 0;
int x = 0;
int deadband = HTPIR_DEFAULT_DEADBAND;
nxtDisplayCenteredTextLine(0, "HiTechnic");
nxtDisplayCenteredBigTextLine(1, "PIR");
nxtDisplayCenteredTextLine(3, "Test 1");
nxtDisplayCenteredTextLine(6, "L/ENTER/R");
nxtDisplayCenteredTextLine(7, "change deadband");
wait1Msec(2000);
eraseDisplay();
while(true) {
if (nNxtButtonPressed != kNoButton)
{
switch (nNxtButtonPressed)
{
case kRightButton: deadband++; break;
case kLeftButton: deadband--; break;
case kEnterButton: deadband = HTPIR_DEFAULT_DEADBAND; break;
}
deadband = clip(deadband, 0, 47);
while (nNxtButtonPressed != kNoButton) EndTimeSlice();
HTPIRsetDeadband(HTPIR, deadband);
}
reading = HTPIRreadSensor(HTPIR);
nxtDisplayTextLine(0, "HT PIR %d / %d", deadband, reading);
x = (40 * reading) / 100;
drawStickFigure(x);
wait1Msec(50);
}
}