Can detect even the slightest finger movement from 10m. Person walking towards at 50m. Perpendicular path at 100m.
These results require good lighting. It fails when the moving object is the same color as it's background of course.
It works better when there is texture on the background and moving object.
Some parameters require tweaking when it's darker in the room.
A bright window in an otherwise dim room causes problems, the shadows have noise.
It fails to detect a laser dot in the dark, but I've solved that on PC!
It detects a static change to the scene, yet ignores moving shadows by resetting every 200 samples.
It detects fast motion like a baseball being thrown across frame.
Can send the picture to PC for display when detected.
#define FLUSH Serial.flush()
#define WR(s) Serial.print(s)
#define WR13 Serial.write(10);
#define WR32 Serial.write(32);
#define HALT {while(1);}
#define CMD(x,var) for(cii=0;cii<x;cii++)Serial.print(var[cii])
//#define DEBUG1 WR13 for(i=0;i<5;i++){Serial.print( int(Serial.read()),HEX);WR32} WR13
//#define DEBUG2 WR13 for(i=0;i<5;i++){Serial.print(char(Serial.read()) );WR32} WR13
char length[] ={0,0,0,0};
char cmdRST[] ={0x56,0,0x26,0}; //reset then >10ms
char cmdCAP[] ={0x56,0,0x36,1,0};
char cmdLEN[] ={0x56,0,0x34,1,0};
char cmdCON[] ={0x56,0,0x36,1,2};
char cmdGET[] ={0x56,0,0x32,0x0c,0,10,0,0,0,0,0,0,0,0,0,10}; //x=16 10*0.01ms
//x=9:
//0x36,d10-80 56k-8k from CommTool, here 40-255
char cmdCMP[] ={0x56,0,0x31,5,1,1,0x12,4,0x36};
char cmd640[] ={0x56,0,0x31,5,4,1,0,0x19,0};
char cmd320[] ={0x56,0,0x31,5,4,1,0,0x19,0x11};
char cmdOFF[] ={0x56,0,0x3e,3,0,1,1}; //[6]=1,0 x=7,30ma,60ma
char cmdBAU[] ={0x56,0,0x24,3,1,0xae,0xc8}; //9600
int i,j,k,last,cii,dlen,cnt=0,a[10];
unsigned int picLen;
boolean same2x=0;
void setup(){
pinMode(13,OUTPUT);
Serial.begin(115200);
CMD(4,cmdRST);delay(500);FLUSH; //need time to get long string
//CMD(7,cmdBAU);delay(500);Serial.begin(9600);
cmdCMP[8]=200;
CMD(9,cmdCMP);delay(10);
//CMD(9,cmd640);delay(10); //remembers even with long power off how? causes image corrupt?
//still in R buffer OK?
}
void loop(){
for(k=0,j=0;j<10;j++){
digitalWrite(13,1);
CMD(5,cmdCAP);delay(60); //try while instead?
digitalWrite(13,0);
CMD(5,cmdLEN);
FLUSH; //wrong order on purpose
while(Serial.available()<9) ;
for(i=0;i<5;i++)Serial.read();
for(i=0;i<4;i++)length[i]=Serial.read();
//if(Serial.available())WR("Err");
picLen=((unsigned int)length[2])*256 +int(length[3]);
if(j<9)CMD(5,cmdCON); //delay(10);
k+=picLen/30;
a[j]=picLen/30;
} //for
WR13
i=abs(k-last)/5-6;
if(i<0)i=0;
WR(dlen=i);WR32
for(j=0,i=0;i<10;i++)
j+=abs(a[i]-k/10);
j-=50;
if(j<0)j=0;
WR(j/5);WR32
cnt++;
if(((dlen>=5)||(j>=10))&&(cnt>5)) { //20,cnt>50? 5,2
WR13
//getdata(picLen);
cnt=0;
same2x=0;
}
CMD(5,cmdCON);
if(abs(k-last)/5<=2)same2x=1;
if(cnt%200==0)same2x=0; //200
if(!same2x)
last=k;
//delay(500);
}
void getdata(unsigned int len){
const int BSIZE=64;
int count=len/BSIZE;
int tail=len&(BSIZE-1);
unsigned int addr=0;
cmdGET[6]=cmdGET[7]=cmdGET[8]=cmdGET[9]=0;
cmdGET[13]=BSIZE;
for(int i=0;i<count;i++){
//cmdGET[15]=10;
CMD(16,cmdGET);
delay(10); //10
if(Serial.available()!=BSIZE+10)HALT
//Serial.read();Serial.read();
//if(Serial.read()!=0x32)Serial.println("Halt?");
FLUSH;
addr+=BSIZE;
cmdGET[8]=addr>>8;
cmdGET[9]=addr;
}
cmdGET[13]=tail;
CMD(16,cmdGET);
delay(100);
//Serial.read();Serial.read();
//if(Serial.read()!=0x32)Serial.println("Halt?");
FLUSH;
}