From 4d3b2637389745242e77ceba65a5e91638f32fdd Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Fri, 3 Dec 2010 15:29:56 -0500 Subject: [PATCH] bug fixes to SD library examples --- .../SD/examples/Datalogger/Datalogger.pde | 2 +- libraries/SD/examples/Files/Files.pde | 28 ++++++++++--------- libraries/SD/examples/ReadWrite/ReadWrite.pde | 3 +- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/libraries/SD/examples/Datalogger/Datalogger.pde b/libraries/SD/examples/Datalogger/Datalogger.pde index 2e22015c1..fd946163f 100644 --- a/libraries/SD/examples/Datalogger/Datalogger.pde +++ b/libraries/SD/examples/Datalogger/Datalogger.pde @@ -34,7 +34,7 @@ void setup() Serial.print("Initializing SD card..."); // make sure that the default chip select pin is set to // output, even if you don't use it: - // pinMode(10, OUTPUT); + pinMode(10, OUTPUT); // see if the card is present and can be initialized: if (!SD.begin(chipSelect)) { diff --git a/libraries/SD/examples/Files/Files.pde b/libraries/SD/examples/Files/Files.pde index 3376c6e50..5b6791f6b 100644 --- a/libraries/SD/examples/Files/Files.pde +++ b/libraries/SD/examples/Files/Files.pde @@ -29,48 +29,50 @@ void setup() // Note that even if it's not used as the CS pin, the hardware SS pin // (10 on most Arduino boards, 53 on the Mega) must be left as an output // or the SD library functions will not work. + pinMode(10, OUTPUT); if (!SD.begin(4)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); - + if (SD.exists("example.txt")) { - Serial.println("example.txt exists."); + Serial.println("example.txt exists."); } else { - Serial.println("example.txt doesn't exist."); + Serial.println("example.txt doesn't exist."); } - + // open a new file and immediately close it: Serial.println("Creating example.txt..."); - myFile = SD.open("example.txt", FILE_TRUNCATE); - myFile.close(); - + myFile = SD.open("example.txt", FILE_TRUNCATE); + myFile.close(); + // Check to see if the file exists: if (SD.exists("example.txt")) { - Serial.println("example.txt exists."); + Serial.println("example.txt exists."); } else { - Serial.println("example.txt doesn't exist."); + Serial.println("example.txt doesn't exist."); } - + // delete the file: Serial.println("Removing example.txt..."); SD.remove("example.txt"); if (SD.exists("example.txt")){ - Serial.println("example.txt exists."); + Serial.println("example.txt exists."); } else { - Serial.println("example.txt doesn't exist."); + Serial.println("example.txt doesn't exist."); } } void loop() { - // nothing happens after setup finishes. + // nothing happens after setup finishes. } + diff --git a/libraries/SD/examples/ReadWrite/ReadWrite.pde b/libraries/SD/examples/ReadWrite/ReadWrite.pde index 4fe531ab9..668fb0b6b 100644 --- a/libraries/SD/examples/ReadWrite/ReadWrite.pde +++ b/libraries/SD/examples/ReadWrite/ReadWrite.pde @@ -30,7 +30,8 @@ void setup() // Note that even if it's not used as the CS pin, the hardware SS pin // (10 on most Arduino boards, 53 on the Mega) must be left as an output // or the SD library functions will not work. - + pinMode(10, OUTPUT); + if (!SD.begin(4)) { Serial.println("initialization failed!"); return;