   {
 
     Serial.println("Capture Done!");
-    
+    //Construct a file name
+    k = k + 1;
+    itoa(k, str, 10); 
+    strcat(str,".jpg");
+    //Open the new file  
+    outFile = SD.open(str,O_WRITE | O_CREAT | O_TRUNC);
+    if (! outFile) 
+    { 
+      Serial.println("open file failed");
+      return;
+    }
     total_time = millis();
     //Read first dummy byte
     //myCAM.read_fifo();

    myCAM.set_mode(MCU2LCD_MODE);
    myCAM.set_format(JPEG);
    myCAM.InitCAM();
    myCAM.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK);		//VSYNC is active HIGH

    //Wait until buttom released

  myCAM.set_format(BMP);

  myCAM.InitCAM();

  
  //Initialize SD Card
  if (!SD.begin(SD_CS)) 
