Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

64 rindas
1.8KB

  1. /*
  2. * Append Example
  3. *
  4. * This sketch shows how to use open for append.
  5. * The sketch will append 100 line each time it opens the file.
  6. * The sketch will open and close the file 100 times.
  7. */
  8. #include <SdFat.h>
  9. // SD chip select pin
  10. const uint8_t chipSelect = SS;
  11. // file system object
  12. SdFat sd;
  13. // create Serial stream
  14. ArduinoOutStream cout(Serial);
  15. // store error strings in flash to save RAM
  16. #define error(s) sd.errorHalt_P(PSTR(s))
  17. //------------------------------------------------------------------------------
  18. void setup() {
  19. // filename for this example
  20. char name[] = "APPEND.TXT";
  21. Serial.begin(9600);
  22. while (!Serial) {} // wait for Leonardo
  23. // pstr() stores strings in flash to save RAM
  24. cout << endl << pstr("Type any character to start\n");
  25. while (Serial.read() <= 0) {}
  26. delay(400); // Catch Due reset problem
  27. // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  28. // breadboards. use SPI_FULL_SPEED for better performance.
  29. if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
  30. cout << pstr("Appending to: ") << name;
  31. for (uint8_t i = 0; i < 100; i++) {
  32. // open stream for append
  33. ofstream sdout(name, ios::out | ios::app);
  34. if (!sdout) error("open failed");
  35. // append 100 lines to the file
  36. for (uint8_t j = 0; j < 100; j++) {
  37. // use int() so byte will print as decimal number
  38. sdout << "line " << int(j) << " of pass " << int(i);
  39. sdout << " millis = " << millis() << endl;
  40. }
  41. // close the stream
  42. sdout.close();
  43. if (!sdout) error("append data failed");
  44. // output progress indicator
  45. if (i % 25 == 0) cout << endl;
  46. cout << '.';
  47. }
  48. cout << endl << "Done" << endl;
  49. }
  50. //------------------------------------------------------------------------------
  51. void loop() {}