choong87 发表于 2013-3-30 21:39:50

照片存入记忆卡模块的问题~帮帮忙!

我在网上找到一些有关我project的源代码,可是我面对的问题是拍第一张照片存入记忆模块没问题,可是再拍第二张存入记忆模块是就发生第二张照片覆盖了第一张照片。
哪一位高手能够帮帮忙~谢谢

#include <MemoryCard.h>
#include <SdFat.h>
#include <JPEGCamera.h>
#include <NewSoftSerial.h>
int sw=4;
//Create an instance of the camera
JPEGCamera camera;

//Create a character array to store the cameras response to commands
char response;
//Count is used to store the number of characters in the response string.
unsigned int count=0;
//Size will be set to the size of the jpeg image.
int size=0;
//This will keep track of the data address being read from the camera
int address=0;
//eof is a flag for the sketch to determine when the end of a file is detected
//while reading the file data from the camera.
int eof=0;
char name[]="0.jpg";


void setup()
{
    //Setup the camera, serial port and memory card
    camera.begin();
    Serial.begin(9600);
    MemoryCard.begin();
    pinMode(sw,INPUT);   
}

void loop()
{
int pbb=digitalRead(sw);
if(pbb==HIGH){
//Reset the camera
    count=camera.reset(response);
    delay(3000);
   
    //Take a picture
    count=camera.takePicture(response);
    //Print the response to the 'TAKE_PICTURE' command.
    Serial.write((const uint8_t*)response, count);
    Serial.println();
   
    //Get the size of the picture
    count = camera.getSize(response, &size);
    //Print the size
    Serial.print("Size: ");
    Serial.println(size);
   
    //Create a file called 'test.txt' on the SD card.
    //NOTE: The memoryCard libary can only create text files.
    //The file has to be renamed to .jpg when copied to a computer.
    MemoryCard.open(name,true);
name+1;
   
    //Starting at address 0, keep reading data until we've read 'size' data.
    while(address < size)
    {
      //Read the data starting at the current address.
      count=camera.readData(response, address);
      //Store all of the data that we read to the SD card
      for(int i=0; i<count; i++){
            //Check the response for the eof indicator (0xFF, 0xD9). If we find it, set the eof flag
            if((response == (char)0xD9) && (response==(char)0xFF))eof=1;
            //Save the data to the SD card
            MemoryCard.file.print(response, BYTE);
            //If we found the eof character, get out of this loop and stop reading data
            if(eof==1)break;
      }
      //Increment the current address by the number of bytes we read
      address+=count;
      //Make sure we stop reading data if the eof flag is set.
      if(eof==1)break;
    }
    //Close the file
   MemoryCard.close();
   Serial.print("Done.");
}
}

histamine 发表于 2013-3-30 22:38:51

=》char name[]="0.jpg";
文件名称每拍一张照片就要改变下啊:)

LZ可以参考下
https://github.com/adafruit/Adafruit-VC0706-Serial-Camera-Library/blob/master/examples/Snapshot/Snapshot.pde
的代码

choong87 发表于 2013-3-30 23:41:08

谢谢哦~有参考过,我再试试看~谢谢帮忙,辛苦你了:D
页: [1]
查看完整版本: 照片存入记忆卡模块的问题~帮帮忙!