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

« back to all changes in this revision

Viewing changes to libraries/SD/examples/DumpFile/DumpFile.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 file dump
 
3
 
 
4
 This example shows how to read a file from the SD card using the
 
5
 SD library and send it over the serial port.
 
6
        
 
7
 The circuit:
 
8
 * SD card attached to SPI bus as follows:
 
9
 ** MOSI - pin 11
 
10
 ** MISO - pin 12
 
11
 ** CLK - pin 13
 
12
 ** CS - pin 4
 
13
 
 
14
 created  22 December 2010
 
15
 
 
16
 This example code is in the public domain.
 
17
         
 
18
 */
 
19
 
 
20
#include <SD.h>
 
21
 
 
22
// On the Ethernet Shield, CS is pin 4. Note that even if it's not
 
23
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
 
24
// 53 on the Mega) must be left as an output or the SD library
 
25
// functions will not work.
 
26
const int chipSelect = 4;
 
27
 
 
28
void setup()
 
29
{
 
30
  Serial.begin(9600);
 
31
  Serial.print("Initializing SD card...");
 
32
  // make sure that the default chip select pin is set to
 
33
  // output, even if you don't use it:
 
34
  pinMode(10, OUTPUT);
 
35
  
 
36
  // see if the card is present and can be initialized:
 
37
  if (!SD.begin(chipSelect)) {
 
38
    Serial.println("Card failed, or not present");
 
39
    // don't do anything more:
 
40
    return;
 
41
  }
 
42
  Serial.println("card initialized.");
 
43
  
 
44
  // open the file. note that only one file can be open at a time,
 
45
  // so you have to close this one before opening another.
 
46
  File dataFile = SD.open("datalog.txt");
 
47
 
 
48
  // if the file is available, write to it:
 
49
  if (dataFile) {
 
50
    while (dataFile.available()) {
 
51
      Serial.write(dataFile.read());
 
52
    }
 
53
    dataFile.close();
 
54
  }  
 
55
  // if the file isn't open, pop up an error:
 
56
  else {
 
57
    Serial.println("error opening datalog.txt");
 
58
  } 
 
59
}
 
60
 
 
61
void loop()
 
62
{
 
63
}
 
64