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.

преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 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. // Open serial communications and wait for port to open:
  31. Serial.begin(9600);
  32. while (!Serial) {
  33. ; // wait for serial port to connect. Needed for Leonardo only
  34. }
  35. Serial.print("Initializing SD card...");
  36. if (!SD.begin(chipSelect)) {
  37. Serial.println("initialization failed!");
  38. return;
  39. }
  40. Serial.println("initialization done.");
  41. root = SD.open("/");
  42. printDirectory(root, 0);
  43. Serial.println("done!");
  44. }
  45. void loop()
  46. {
  47. // nothing happens after setup finishes.
  48. }
  49. void printDirectory(File dir, int numTabs) {
  50. while(true) {
  51. File entry = dir.openNextFile();
  52. if (! entry) {
  53. // no more files
  54. //Serial.println("**nomorefiles**");
  55. break;
  56. }
  57. for (uint8_t i=0; i<numTabs; i++) {
  58. Serial.print('\t');
  59. }
  60. Serial.print(entry.name());
  61. if (entry.isDirectory()) {
  62. Serial.println("/");
  63. printDirectory(entry, numTabs+1);
  64. } else {
  65. // files have sizes, directories do not
  66. Serial.print("\t\t");
  67. Serial.println(entry.size(), DEC);
  68. }
  69. entry.close();
  70. }
  71. }