Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

OpenNext.ino 1.4KB

5 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 default chip select pin.
  7. const uint8_t chipSelect = SS;
  8. // file system object
  9. SdFat sd;
  10. SdFile root;
  11. SdFile file;
  12. //------------------------------------------------------------------------------
  13. void setup() {
  14. Serial.begin(9600);
  15. // Wait for USB Serial
  16. while (!Serial) {
  17. SysCall::yield();
  18. }
  19. Serial.println("Type any character to start");
  20. while (!Serial.available()) {
  21. SysCall::yield();
  22. }
  23. // Initialize at the highest speed supported by the board that is
  24. // not over 50 MHz. Try a lower speed if SPI errors occur.
  25. if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) {
  26. sd.initErrorHalt();
  27. }
  28. if (!root.open("/")) {
  29. sd.errorHalt("open root failed");
  30. }
  31. // Open next file in root.
  32. // Warning, openNext starts at the current directory position
  33. // so a rewind of the directory may be required.
  34. while (file.openNext(&root, O_RDONLY)) {
  35. file.printFileSize(&Serial);
  36. Serial.write(' ');
  37. file.printModifyDateTime(&Serial);
  38. Serial.write(' ');
  39. file.printName(&Serial);
  40. if (file.isDir()) {
  41. // Indicate a directory.
  42. Serial.write('/');
  43. }
  44. Serial.println();
  45. file.close();
  46. }
  47. if (root.getError()) {
  48. Serial.println("openNext failed");
  49. } else {
  50. Serial.println("Done!");
  51. }
  52. }
  53. //------------------------------------------------------------------------------
  54. void loop() {}