Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ListFiles.ino 1.4KB

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