~ubuntu-branches/debian/experimental/arduino/experimental

« back to all changes in this revision

Viewing changes to libraries/SD/examples/listfiles/listfiles.ino

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2012-03-11 18:19:42 UTC
  • mfrom: (1.1.5) (5.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120311181942-be2clnbz1gcehixb
Tags: 1:1.0.1~rc1+dfsg-1
New upstream release, experimental.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  SD card basic file example
 
3
 
 
4
 This example shows how to create and destroy an SD card file   
 
5
 The circuit:
 
6
 * SD card attached to SPI bus as follows:
 
7
 ** MOSI - pin 11
 
8
 ** MISO - pin 12
 
9
 ** CLK - pin 13
 
10
 ** CS - pin 4
 
11
 
 
12
 created   Nov 2010
 
13
 by David A. Mellis
 
14
 updated 2 Dec 2010
 
15
 by Tom Igoe
 
16
 
 
17
 This example code is in the public domain.
 
18
         
 
19
 */
 
20
#include <SD.h>
 
21
 
 
22
File root;
 
23
 
 
24
void setup()
 
25
{
 
26
  Serial.begin(9600);
 
27
  Serial.print("Initializing SD card...");
 
28
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
 
29
  // Note that even if it's not used as the CS pin, the hardware SS pin 
 
30
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
 
31
  // or the SD library functions will not work. 
 
32
  pinMode(10, OUTPUT);
 
33
 
 
34
  if (!SD.begin(10)) {
 
35
    Serial.println("initialization failed!");
 
36
    return;
 
37
  }
 
38
  Serial.println("initialization done.");
 
39
 
 
40
  root = SD.open("/");
 
41
  
 
42
  printDirectory(root, 0);
 
43
  
 
44
  Serial.println("done!");
 
45
}
 
46
 
 
47
void loop()
 
48
{
 
49
  // nothing happens after setup finishes.
 
50
}
 
51
 
 
52
void printDirectory(File dir, int numTabs) {
 
53
   while(true) {
 
54
     
 
55
     File entry =  dir.openNextFile();
 
56
     if (! entry) {
 
57
       // no more files
 
58
       //Serial.println("**nomorefiles**");
 
59
       break;
 
60
     }
 
61
     for (uint8_t i=0; i<numTabs; i++) {
 
62
       Serial.print('\t');
 
63
     }
 
64
     Serial.print(entry.name());
 
65
     if (entry.isDirectory()) {
 
66
       Serial.println("/");
 
67
       printDirectory(entry, numTabs+1);
 
68
     } else {
 
69
       // files have sizes, directories do not
 
70
       Serial.print("\t\t");
 
71
       Serial.println(entry.size(), DEC);
 
72
     }
 
73
   }
 
74
}
 
75
 
 
76
 
 
77