Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

95 lines
2.0KB

  1. /*
  2. SD card basic file example
  3. This example shows how to create and destroy an SD card file
  4. The circuit:
  5. * SD card attached to SPI bus as follows:
  6. ** MOSI - pin 11, pin 7 on Teensy with audio board
  7. ** MISO - pin 12
  8. ** CLK - pin 13, pin 14 on Teensy with audio board
  9. ** CS - pin 4, pin 10 on Teensy with audio board
  10. created Nov 2010
  11. by David A. Mellis
  12. modified 9 Apr 2012
  13. by Tom Igoe
  14. This example code is in the public domain.
  15. */
  16. #include <SD.h>
  17. #include <SPI.h>
  18. File root;
  19. // change this to match your SD shield or module;
  20. // Arduino Ethernet shield: pin 4
  21. // Adafruit SD shields and modules: pin 10
  22. // Sparkfun SD shield: pin 8
  23. // Teensy audio board: pin 10
  24. // Wiz820+SD board: pin 4
  25. // Teensy 2.0: pin 0
  26. // Teensy++ 2.0: pin 20
  27. const int chipSelect = 4;
  28. void setup()
  29. {
  30. //UNCOMMENT THESE TWO LINES FOR TEENSY AUDIO BOARD:
  31. //SPI.setMOSI(7); // Audio shield has MOSI on pin 7
  32. //SPI.setSCK(14); // Audio shield has SCK on pin 14
  33. // Open serial communications and wait for port to open:
  34. Serial.begin(9600);
  35. while (!Serial) {
  36. ; // wait for serial port to connect. Needed for Leonardo only
  37. }
  38. Serial.print("Initializing SD card...");
  39. if (!SD.begin(chipSelect)) {
  40. Serial.println("initialization failed!");
  41. return;
  42. }
  43. Serial.println("initialization done.");
  44. root = SD.open("/");
  45. printDirectory(root, 0);
  46. Serial.println("done!");
  47. }
  48. void loop()
  49. {
  50. // nothing happens after setup finishes.
  51. }
  52. void printDirectory(File dir, int numTabs) {
  53. while(true) {
  54. File entry = dir.openNextFile();
  55. if (! entry) {
  56. // no more files
  57. //Serial.println("**nomorefiles**");
  58. break;
  59. }
  60. for (uint8_t i=0; i<numTabs; i++) {
  61. Serial.print('\t');
  62. }
  63. Serial.print(entry.name());
  64. if (entry.isDirectory()) {
  65. Serial.println("/");
  66. printDirectory(entry, numTabs+1);
  67. } else {
  68. // files have sizes, directories do not
  69. Serial.print("\t\t");
  70. Serial.println(entry.size(), DEC);
  71. }
  72. entry.close();
  73. }
  74. }