极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9202|回复: 2

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

[复制链接]
发表于 2013-3-30 21:39:50 | 显示全部楼层 |阅读模式
我在网上找到一些有关我project的源代码,可是我面对的问题是拍第一张照片存入记忆模块没问题,可是再拍第二张存入记忆模块是就发生第二张照片覆盖了第一张照片。
哪一位高手能够帮帮忙~谢谢

  1. #include <MemoryCard.h>
  2. #include <SdFat.h>
  3. #include <JPEGCamera.h>
  4. #include <NewSoftSerial.h>
  5. int sw=4;
  6. //Create an instance of the camera
  7. JPEGCamera camera;

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


  20. void setup()
  21. {
  22.     //Setup the camera, serial port and memory card
  23.     camera.begin();
  24.     Serial.begin(9600);
  25.     MemoryCard.begin();
  26.     pinMode(sw,INPUT);   
  27. }

  28. void loop()
  29. {
  30.   int pbb=digitalRead(sw);
  31.   if(pbb==HIGH){
  32. //Reset the camera
  33.     count=camera.reset(response);
  34.     delay(3000);
  35.    
  36.     //Take a picture
  37.     count=camera.takePicture(response);
  38.     //Print the response to the 'TAKE_PICTURE' command.
  39.     Serial.write((const uint8_t*)response, count);
  40.     Serial.println();
  41.    
  42.     //Get the size of the picture
  43.     count = camera.getSize(response, &size);
  44.     //Print the size
  45.     Serial.print("Size: ");
  46.     Serial.println(size);
  47.    
  48.     //Create a file called 'test.txt' on the SD card.
  49.     //NOTE: The memoryCard libary can only create text files.
  50.     //The file has to be renamed to .jpg when copied to a computer.
  51.     MemoryCard.open(name,true);
  52.   name+1;
  53.    
  54.     //Starting at address 0, keep reading data until we've read 'size' data.
  55.     while(address < size)
  56.     {
  57.         //Read the data starting at the current address.
  58.         count=camera.readData(response, address);
  59.         //Store all of the data that we read to the SD card
  60.         for(int i=0; i<count; i++){
  61.             //Check the response for the eof indicator (0xFF, 0xD9). If we find it, set the eof flag
  62.             if((response[i] == (char)0xD9) && (response[i-1]==(char)0xFF))eof=1;
  63.             //Save the data to the SD card
  64.             MemoryCard.file.print(response[i], BYTE);
  65.             //If we found the eof character, get out of this loop and stop reading data
  66.             if(eof==1)break;
  67.         }
  68.         //Increment the current address by the number of bytes we read
  69.         address+=count;
  70.         //Make sure we stop reading data if the eof flag is set.
  71.         if(eof==1)break;
  72.     }
  73.     //Close the file
  74.      MemoryCard.close();
  75.      Serial.print("Done.");
  76. }
  77. }
复制代码
回复

使用道具 举报

发表于 2013-3-30 22:38:51 | 显示全部楼层
=》char name[]="0.jpg";
文件名称每拍一张照片就要改变下啊

LZ可以参考下
https://github.com/adafruit/Adaf ... apshot/Snapshot.pde
的代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-3-30 23:41:08 | 显示全部楼层
谢谢哦~有参考过,我再试试看~谢谢帮忙,辛苦你了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-6-2 00:23 , Processed in 0.088436 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表