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 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <SerialFlash.h>
  2. #include <SPI.h>
  3. const int FlashChipSelect = 6;
  4. void setup() {
  5. //uncomment these if using Teensy audio shield
  6. //SPI.setSCK(14); // Audio shield has SCK on pin 14
  7. //SPI.setMOSI(7); // Audio shield has MOSI on pin 7
  8. //uncomment these if you have other SPI chips connected
  9. //to keep them disabled while using only SerialFlash
  10. //pinMode(4, INPUT_PULLUP);
  11. //pinMode(10, INPUT_PULLUP);
  12. // wait for Arduino Serial Monitor
  13. while (!Serial) ;
  14. delay(100);
  15. Serial.println("All Files on SPI Flash chip:");
  16. if (!SerialFlash.begin()) {
  17. error("Unable to access SPI Flash chip");
  18. }
  19. SerialFlash.opendir();
  20. unsigned int count = 0;
  21. while (1) {
  22. char filename[64];
  23. unsigned long filesize;
  24. if (SerialFlash.readdir(filename, sizeof(filename), filesize)) {
  25. Serial.print(" ");
  26. Serial.print(filename);
  27. spaces(20 - strlen(filename));
  28. Serial.print(" ");
  29. Serial.print(filesize);
  30. Serial.print(" bytes");
  31. Serial.println();
  32. } else {
  33. break; // no more files
  34. }
  35. }
  36. }
  37. void spaces(int num) {
  38. for (int i=0; i < num; i++) {
  39. Serial.print(" ");
  40. }
  41. }
  42. void loop() {
  43. }
  44. void error(const char *message) {
  45. while (1) {
  46. Serial.println(message);
  47. delay(2500);
  48. }
  49. }