We have got the TTL camera working.
Now we are trying to integrate it with a PIR sensor.
The code is below: I would think that we would turn the cam motion detect to off
and then adding the PIR sensor.
Any suggestions?
Thanks
Code: Select all
// Motion detection system can alert you when the camera 'sees' motion!
cam.setMotionDetect(true); // turn it on
//cam.setMotionDetect(false); // turn it off (default)
// You can also verify whether motion detection is active!
Serial.print("Motion detection is ");
if (cam.getMotionDetect())
Serial.println("ON");
else
Serial.println("OFF");
}
void loop() {
if (cam.motionDetected()) {
Serial.println("Motion!");
cam.setMotionDetect(false);
if (! cam.takePicture())
Serial.println("Failed to snap!");
else
Serial.println("Picture taken!");
char filename[13];
strcpy(filename, "IMAGE00.JPG");
for (int i = 0; i < 100; i++) {
filename[5] = '0' + i/10;
filename[6] = '0' + i%10;
// create if does not exist, do not open existing, write, sync after write
if (! SD.exists(filename)) {
break;
}
}
File imgFile = SD.open(filename, FILE_WRITE);
uint16_t jpglen = cam.frameLength();
Serial.print(jpglen, DEC);
Serial.println(" byte image");
Serial.print("Writing image to "); Serial.print(filename);
while (jpglen > 0) {
// read 32 bytes at a time;
uint8_t *buffer;
uint8_t bytesToRead = min(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
buffer = cam.readPicture(bytesToRead);
imgFile.write(buffer, bytesToRead);
//Serial.print("Read "); Serial.print(bytesToRead, DEC); Serial.println(" bytes");
jpglen -= bytesToRead;
}
imgFile.close();
Serial.println("...Done!");
cam.resumeVideo();
cam.setMotionDetect(true);
}