Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

94 Zeilen
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
  7. ** MISO - pin 12
  8. ** CLK - pin 13
  9. ** CS - pin 4
  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 2.0: pin 0
  24. // Teensy++ 2.0: pin 20
  25. const int chipSelect = 10;
  26. void setup()
  27. {
  28. // Open serial communications and wait for port to open:
  29. Serial.begin(9600);
  30. while (!Serial) {
  31. ; // wait for serial port to connect. Needed for Leonardo only
  32. }
  33. Serial.print("Initializing SD card...");
  34. // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  35. // Note that even if it's not used as the CS pin, the hardware SS pin
  36. // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  37. // or the SD library functions will not work.
  38. pinMode(10, OUTPUT);
  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. }