You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1KB

  1. /*
  2. * Print size, modify date/time, and name for all files in root.
  3. */
  4. #include <SPI.h>
  5. #include <SdFat.h>
  6. // SD chip select pin
  7. const uint8_t chipSelect = SS;
  8. // file system object
  9. SdFat sd;
  10. SdFile file;
  11. //------------------------------------------------------------------------------
  12. void setup() {
  13. Serial.begin(9600);
  14. while (!Serial) {} // wait for Leonardo
  15. delay(1000);
  16. // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  17. // breadboards. use SPI_FULL_SPEED for better performance.
  18. if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
  19. // open next file in root. The volume working directory, vwd, is root
  20. while (file.openNext(sd.vwd(), O_READ)) {
  21. file.printFileSize(&Serial);
  22. Serial.write(' ');
  23. file.printModifyDateTime(&Serial);
  24. Serial.write(' ');
  25. file.printName(&Serial);
  26. if (file.isDir()) {
  27. // Indicate a directory.
  28. Serial.write('/');
  29. }
  30. Serial.println();
  31. file.close();
  32. }
  33. Serial.println("Done!");
  34. }
  35. //------------------------------------------------------------------------------
  36. void loop() {}