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.

55 lines
1.1KB

  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. // wait for Arduino Serial Monitor
  9. while (!Serial) ;
  10. delay(100);
  11. Serial.println("All Files on SPI Flash chip:");
  12. if (!SerialFlash.begin()) {
  13. error("Unable to access SPI Flash chip");
  14. }
  15. SerialFlash.opendir();
  16. unsigned int count = 0;
  17. while (1) {
  18. char filename[64];
  19. unsigned long filesize;
  20. if (SerialFlash.readdir(filename, sizeof(filename), filesize)) {
  21. Serial.print(" ");
  22. Serial.print(filename);
  23. spaces(20 - strlen(filename));
  24. Serial.print(" ");
  25. Serial.print(filesize);
  26. Serial.print(" bytes");
  27. Serial.println();
  28. } else {
  29. break; // no more files
  30. }
  31. }
  32. }
  33. void spaces(int num) {
  34. for (int i=0; i < num; i++) {
  35. Serial.print(" ");
  36. }
  37. }
  38. void loop() {
  39. }
  40. void error(const char *message) {
  41. while (1) {
  42. Serial.println(message);
  43. delay(2500);
  44. }
  45. }