//A test file to see if I can combine libraries and example code for // - reading an SD card (from https://www.arduino.cc/en/Tutorial/listfiles) // - diplaying text on an LCD screen (from openGLCD Library - Hello World sketch) // //Andrew Sleigh //2018-04-20 // // * SD card attached to SPI bus as follows: // ** MOSI - pin 11 // ** MISO - pin 12 // ** CLK - pin 13 // ** CS - varies, see below // SD card setup #include #include File root; String fileList = "Blah"; // LCD screen setup #include void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only // Initialize the GLCD GLCD.Init(); // Select the font for the default text area GLCD.SelectFont(System5x7); } Serial.print("Initializing SD card..."); if (!SD.begin(12)) { Serial.println("initialization failed!"); while (1); } Serial.println("initialization done."); root = SD.open("/"); printDirectory(root, 0); Serial.println("done!"); } void loop() { // nothing happens after setup finishes. } void printDirectory(File dir, int numTabs) { // loop through all the files in the root directory while (true) { File entry = dir.openNextFile(); if (! entry) { // no more files break; } // I only want it to print directories, not files if (entry.isDirectory()) { // Serial.println("/"); for (uint8_t i = 0; i < numTabs; i++) { Serial.print('\t'); } // entry.name() is the title of each file or folder it finds Serial.println(entry.name()); // Also print it to the LCD screen GLCD.println(entry.name()); // this loop recursively goes through directories and also prints what it finds inside // I don't want this, so comment it out // printDirectory(entry, numTabs + 1); } else { // ignore files } entry.close(); } }