mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
SD library updates. Renaming makeDir() to mkdir(). Replacing example. Adding keywords.txt.
This commit is contained in:
parent
fcc4188b15
commit
5af5619df4
@ -404,7 +404,7 @@ boolean SDClass::exists(char *filepath) {
|
||||
//}
|
||||
|
||||
|
||||
boolean SDClass::makeDir(char *filepath) {
|
||||
boolean SDClass::mkdir(char *filepath) {
|
||||
/*
|
||||
|
||||
Makes a single directory or a heirarchy of directories.
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
|
||||
// Create the requested directory heirarchy--if intermediate directories
|
||||
// do not exist they will be created.
|
||||
boolean makeDir(char *filepath);
|
||||
boolean mkdir(char *filepath);
|
||||
|
||||
private:
|
||||
SdFile file;
|
||||
|
@ -1,114 +0,0 @@
|
||||
/*
|
||||
|
||||
A sketch to demonstrate the features of the SD library.
|
||||
|
||||
*/
|
||||
|
||||
#include <SD.h>
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
|
||||
// You always need to initialise the SD library
|
||||
Serial.println("Init SD...");
|
||||
SD.begin();
|
||||
|
||||
|
||||
// This demonstrates making a directory hierarchy
|
||||
Serial.println();
|
||||
Serial.println("Make directory...");
|
||||
SD.makeDir("/apple/banana/cabbage/");
|
||||
|
||||
|
||||
// You can check for the existence of specific files/directories
|
||||
char *filePathOne = "/apple/banana/cabbage/";
|
||||
char *filePathTwo = "/apple/banana/cabbage/dog/";
|
||||
|
||||
Serial.println();
|
||||
|
||||
Serial.print(filePathOne);
|
||||
Serial.print(" does ");
|
||||
if (SD.exists(filePathOne)) {
|
||||
Serial.println("exist.");
|
||||
} else {
|
||||
Serial.println("not exist.");
|
||||
}
|
||||
|
||||
Serial.print(filePathTwo);
|
||||
Serial.print(" does ");
|
||||
if (SD.exists(filePathTwo)) {
|
||||
Serial.println("exist.");
|
||||
} else {
|
||||
Serial.println("not exist.");
|
||||
}
|
||||
|
||||
|
||||
// Demonstrate writing (and appending to existing file content)
|
||||
// to a file in a subdirectory
|
||||
Serial.println();
|
||||
Serial.println("Writing to 'dolphin.txt'.");
|
||||
|
||||
SD.open("/apple/banana/cabbage/dolphin.txt", true);
|
||||
|
||||
SD.file.println("This line was appended to the file.");
|
||||
|
||||
SD.close();
|
||||
|
||||
|
||||
// Demonstrate writing to a file in the root directory and overwriting any
|
||||
// existing content
|
||||
Serial.println();
|
||||
Serial.println("Writing to 'top.txt'.");
|
||||
|
||||
SD.open("/top.txt", true, false);
|
||||
|
||||
SD.file.println("This line overwrote the previous content of the file.");
|
||||
|
||||
SD.close();
|
||||
|
||||
|
||||
// Demonstrate reading from a file in a subdirectory
|
||||
Serial.println();
|
||||
Serial.println("Reading 'dolphin.txt':");
|
||||
|
||||
SD.open("/apple/banana/cabbage/dolphin.txt");
|
||||
|
||||
int c;
|
||||
|
||||
// This approach may be easier to follow
|
||||
while(true) {
|
||||
c = SD.file.read();
|
||||
if (c < 0) {
|
||||
break;
|
||||
}
|
||||
Serial.print((char) c);
|
||||
}
|
||||
|
||||
SD.close();
|
||||
|
||||
|
||||
// Demonstrate reading from a file in the root directory in a slightly different way
|
||||
Serial.println();
|
||||
Serial.println("Reading 'top.txt':");
|
||||
|
||||
SD.open("/top.txt");
|
||||
|
||||
// This approach is more compact
|
||||
while((c = SD.file.read()) >= 0) {
|
||||
Serial.print((char) c);
|
||||
}
|
||||
|
||||
SD.close();
|
||||
|
||||
|
||||
// Demonstration complete!
|
||||
Serial.println();
|
||||
Serial.println("Done.");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
|
||||
|
36
libraries/SD/examples/ReadWrite/ReadWrite.pde
Normal file
36
libraries/SD/examples/ReadWrite/ReadWrite.pde
Normal file
@ -0,0 +1,36 @@
|
||||
#include <SD.h>
|
||||
|
||||
File f;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.print("Initializing SD card...");
|
||||
SD.begin();
|
||||
Serial.println("done.");
|
||||
|
||||
f = SD.open("test.txt", true, false);
|
||||
if (f) {
|
||||
Serial.print("Writing to test.txt...");
|
||||
f.println("testing 1, 2, 3.");
|
||||
f.close();
|
||||
Serial.println("done.");
|
||||
} else {
|
||||
Serial.println("error opening test.txt");
|
||||
}
|
||||
|
||||
f = SD.open("test.txt");
|
||||
if (f) {
|
||||
Serial.println("test.txt:");
|
||||
while (f.available()) Serial.write(f.read());
|
||||
f.close();
|
||||
} else {
|
||||
Serial.println("error opening test.txt");
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
23
libraries/SD/keywords.txt
Normal file
23
libraries/SD/keywords.txt
Normal file
@ -0,0 +1,23 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map SD
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
SD KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
begin KEYWORD2
|
||||
exists KEYWORD2
|
||||
mkdir KEYWORD2
|
||||
open KEYWORD2
|
||||
close KEYWORD2
|
||||
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
Loading…
Reference in New Issue
Block a user