Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

40 lines
1.1KB

  1. /*
  2. * Read the logfile created by the eventlog.pde example.
  3. * Demo of pathnames and working directories
  4. */
  5. #include <SdFat.h>
  6. // SD chip select pin
  7. const uint8_t chipSelect = SS;
  8. // file system object
  9. SdFat sd;
  10. // define a serial output stream
  11. ArduinoOutStream cout(Serial);
  12. //------------------------------------------------------------------------------
  13. void setup() {
  14. int c;
  15. Serial.begin(9600);
  16. while (!Serial) {} // wait for Leonardo
  17. // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  18. // breadboards. use SPI_FULL_SPEED for better performance.
  19. if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
  20. // set current working directory
  21. if (!sd.chdir("LOGS/2011/JAN/")) {
  22. sd.errorHalt("chdir failed. Did you run eventlog.pde?");
  23. }
  24. // open file in current working directory
  25. ifstream file("LOGFILE.TXT");
  26. if (!file.is_open()) sd.errorHalt("open failed");
  27. // copy the file to Serial
  28. while ((c = file.get()) >= 0) cout << (char)c;
  29. cout << "Done" << endl;
  30. }
  31. //------------------------------------------------------------------------------
  32. void loop() {}