mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-06 01:08:25 +01:00
bug fixes to SD library examples
This commit is contained in:
parent
86e3d4ad7a
commit
4d3b263738
@ -34,7 +34,7 @@ void setup()
|
|||||||
Serial.print("Initializing SD card...");
|
Serial.print("Initializing SD card...");
|
||||||
// make sure that the default chip select pin is set to
|
// make sure that the default chip select pin is set to
|
||||||
// output, even if you don't use it:
|
// output, even if you don't use it:
|
||||||
// pinMode(10, OUTPUT);
|
pinMode(10, OUTPUT);
|
||||||
|
|
||||||
// see if the card is present and can be initialized:
|
// see if the card is present and can be initialized:
|
||||||
if (!SD.begin(chipSelect)) {
|
if (!SD.begin(chipSelect)) {
|
||||||
|
@ -29,48 +29,50 @@ void setup()
|
|||||||
// Note that even if it's not used as the CS pin, the hardware SS pin
|
// 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
|
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
|
||||||
// or the SD library functions will not work.
|
// or the SD library functions will not work.
|
||||||
|
pinMode(10, OUTPUT);
|
||||||
|
|
||||||
if (!SD.begin(4)) {
|
if (!SD.begin(4)) {
|
||||||
Serial.println("initialization failed!");
|
Serial.println("initialization failed!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Serial.println("initialization done.");
|
Serial.println("initialization done.");
|
||||||
|
|
||||||
if (SD.exists("example.txt")) {
|
if (SD.exists("example.txt")) {
|
||||||
Serial.println("example.txt exists.");
|
Serial.println("example.txt exists.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Serial.println("example.txt doesn't exist.");
|
Serial.println("example.txt doesn't exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// open a new file and immediately close it:
|
// open a new file and immediately close it:
|
||||||
Serial.println("Creating example.txt...");
|
Serial.println("Creating example.txt...");
|
||||||
myFile = SD.open("example.txt", FILE_TRUNCATE);
|
myFile = SD.open("example.txt", FILE_TRUNCATE);
|
||||||
myFile.close();
|
myFile.close();
|
||||||
|
|
||||||
// Check to see if the file exists:
|
// Check to see if the file exists:
|
||||||
if (SD.exists("example.txt")) {
|
if (SD.exists("example.txt")) {
|
||||||
Serial.println("example.txt exists.");
|
Serial.println("example.txt exists.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Serial.println("example.txt doesn't exist.");
|
Serial.println("example.txt doesn't exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete the file:
|
// delete the file:
|
||||||
Serial.println("Removing example.txt...");
|
Serial.println("Removing example.txt...");
|
||||||
SD.remove("example.txt");
|
SD.remove("example.txt");
|
||||||
|
|
||||||
if (SD.exists("example.txt")){
|
if (SD.exists("example.txt")){
|
||||||
Serial.println("example.txt exists.");
|
Serial.println("example.txt exists.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Serial.println("example.txt doesn't exist.");
|
Serial.println("example.txt doesn't exist.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// nothing happens after setup finishes.
|
// nothing happens after setup finishes.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,7 +30,8 @@ void setup()
|
|||||||
// Note that even if it's not used as the CS pin, the hardware SS pin
|
// 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
|
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
|
||||||
// or the SD library functions will not work.
|
// or the SD library functions will not work.
|
||||||
|
pinMode(10, OUTPUT);
|
||||||
|
|
||||||
if (!SD.begin(4)) {
|
if (!SD.begin(4)) {
|
||||||
Serial.println("initialization failed!");
|
Serial.println("initialization failed!");
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user