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