motion detection

Hi there.

I am working on a school project and I need a program that pans a servo back and forth and takes readings from an Eltec 442-3 sensor mounted on the servo. If there is a detection I want a relay to be activated.

I have found this code for a BrainStem microprocessor, could I use this code??

LINK TO CODE: | Acroname

LINK TO SENSOR: Smart Programmable USB Hubs, Automation Sensors, Manufacturing Test Equipment

I am new in this, so any help would be appreciated... Thanks

Can't use that exact code, but it is simple enough to rewrite and have an understanding of what it does while your rewriting it.

I have made some changes in the BrainStem code
This is how it looks so far:

LINK to the rewrite:
http://www.cuztom.dk/arduino/pyroelectric_scan_test_program_rewrite.pde

Can anyone give me some advises on what I should do next, I still get a few errors...
That I don't know how to deal with:

LINK to the original code:
http://www.cuztom.dk/arduino/pyroelectric_scan_test_program_original.pde

/* pyroelectric scan test program */

int aCore;

int aPrint;
int aServo;
int aA2D;

int PYROIN = 0
int SRVSCAN = 3

int SSTEP = 1
int SCANDELAY = 30
int DTHR = 250

/* global variables for scan statistics */
int max;
int min;
int maxp;
int minp;
int pos1;
int pos2;

/* Resets scan statistics. */

void reset_scan()
{
max = 0;
min = 1023;
maxp = 0;
minp = 0;
}

/* This routine updates the servo position,
delays for a moment, then takes an A2D
reading from the Eltec sensor and updates
the global statistics variables. */

void update_max_min(int npos)
{
int r;
aServo_SetAbsolute(SRVSCAN, (unsigned char)npos);
aCore_Sleep(SCANDELAY);
r = aA2D_ReadInt(PYROIN);
if (r > max) {
max = r;
maxp = npos;
}
if (r < min) {
min = r;
minp = npos;
}
}

/* This routine checks the range between the peaks
and sees if it is big enough to be a valid detection.
If the detection is valid, the function returns the
average of the peak positions. */
int check_min_max()
{
int pos = 0;
int diff;
diff = max - min;
if (diff > DTHR) {
pos = (maxp + minp) / 2;
}
return pos;
}

void main()
{
int i;
int pos1=0;
int pos2=0;

while (1) {
// scan going in one direction
reset_scan();
for (i = 2; i < 254; i = i + SSTEP){
update_max_min(i);
}
pos1=check_min_max();

// scan going in the other direction
reset_scan();
for (i = 254; i >= 2; i = i - SSTEP) {
update_max_min(i);
}
pos2=check_min_max();

// print the position of the hot spot for each scan
// (may vary a little bit depending on direction)
aPrint_IntDec(pos1);
aPrint_Char(&39;,&39;);
aPrint_IntDec(pos2);
aPrint_Char(&39;n&39;);
}
}

THANKS
/Drake