PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
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.

listfiles.ino 2.0KB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. // Teensy 3.5 & 3.6 & 4.1 on-board: BUILTIN_SDCARD
  25. // Wiz820+SD board: pin 4
  26. // Teensy 2.0: pin 0
  27. // Teensy++ 2.0: pin 20
  28. const int chipSelect = 4;
  29. void setup()
  30. {
  31. //UNCOMMENT THESE TWO LINES FOR TEENSY AUDIO BOARD:
  32. //SPI.setMOSI(7); // Audio shield has MOSI on pin 7
  33. //SPI.setSCK(14); // Audio shield has SCK on pin 14
  34. // Open serial communications and wait for port to open:
  35. Serial.begin(9600);
  36. while (!Serial) {
  37. ; // wait for serial port to connect.
  38. }
  39. Serial.print("Initializing SD card...");
  40. if (!SD.begin(chipSelect)) {
  41. Serial.println("initialization failed!");
  42. return;
  43. }
  44. Serial.println("initialization done.");
  45. root = SD.open("/");
  46. printDirectory(root, 0);
  47. Serial.println("done!");
  48. }
  49. void loop()
  50. {
  51. // nothing happens after setup finishes.
  52. }
  53. void printDirectory(File dir, int numTabs) {
  54. while(true) {
  55. File entry = dir.openNextFile();
  56. if (! entry) {
  57. // no more files
  58. //Serial.println("**nomorefiles**");
  59. break;
  60. }
  61. for (uint8_t i=0; i<numTabs; i++) {
  62. Serial.print('\t');
  63. }
  64. Serial.print(entry.name());
  65. if (entry.isDirectory()) {
  66. Serial.println("/");
  67. printDirectory(entry, numTabs+1);
  68. } else {
  69. // files have sizes, directories do not
  70. Serial.print("\t\t");
  71. Serial.println(entry.size(), DEC);
  72. }
  73. entry.close();
  74. }
  75. }