So I am trying to get the camera shield from radio shack to work. It's all connected and set up. The only issue is when the motion detector on the shield is sensed, it takes a picture. I there is already a picture file on there, it deletes the old one. It is under the file name temp.jpg. I need help with the code for making multiple files.
Here is original code (from Github site). It is only a section of the whole thing.
I know the issue is the top few lines. Where it says if file exists already, delete it. Just don't how what to write. I tried what "RoboJoe" said on Radio Shack Camera Shield camsd.pde sketch - writing jpeg files to a SD - Storage - Arduino Forum but no success.
void capture_photo(){
// Check to see if the file exists:
if exists,delete the file: REALLY??? I want more than one image
if(sd.exists("temp.jpg")) sd.remove("temp.jpg");
// open a new empty file for write at end like the Native SD library
if (!myFile.open("temp.jpg", O_RDWR | O_CREAT | O_AT_END)) {
sd.errorHalt("opening temp.jpg for write failed");
// close the file:
myFile.close();
VC0706_compression_ratio(63);
delay(100);
VC0706_frame_control(3);
delay(10);
VC0706_frame_control(0);
delay(10);
rx_ready=false;
rx_counter=0;
Serial.end(); // clear all rx buffer
delay(5);
Serial.begin(115200);
//get frame buffer length
VC0706_get_framebuffer_length(0);
delay(10);
buffer_read();
//while(1){};
// store frame buffer length for coming reading
frame_length=(VC0706_rx_buffer[5]<<8)+VC0706_rx_buffer[6];
frame_length=frame_length<<16;
frame_length=frame_length+(0x0ff00&(VC0706_rx_buffer[7]<<8))+VC0706_rx_buffer[8];
vc_frame_address =READ_DATA_BLOCK_NO;
myFile.open("temp.jpg", O_RDWR);
while(vc_frame_address<frame_length){
VC0706_read_frame_buffer(vc_frame_address-READ_DATA_BLOCK_NO, READ_DATA_BLOCK_NO);
delay(9);
//get the data with length=READ_DATA_BLOCK_NObytes
rx_ready=false;
rx_counter=0;
buffer_read();
// write data to temp.jpg
myFile.write(VC0706_rx_buffer+5,READ_DATA_BLOCK_NO);
//read next READ_DATA_BLOCK_NO bytes from frame buffer
vc_frame_address=vc_frame_address+READ_DATA_BLOCK_NO;
}
// get the last data
vc_frame_address=vc_frame_address-READ_DATA_BLOCK_NO;
last_data_length=frame_length-vc_frame_address;
VC0706_read_frame_buffer(vc_frame_address,last_data_length);
delay(9);
//get the data
rx_ready=false;
rx_counter=0;
buffer_read();
myFile.write(VC0706_rx_buffer+5,last_data_length);
myFile.close();
}}
#endif }