您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

62 行
1.3KB

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