123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #define USE_SD_H 0
- #if USE_SD_H
- #include <SD.h>
- #else
- #include "SdFat.h"
- SdFat SD;
- #endif
- #define SD_CS_PIN SS
- File myFile;
- void setup() {
- Serial.begin(9600);
- while (!Serial) {
- }
- #if USE_SD_H
- Serial.println(F("Using SD.h. Set USE_SD_H zero to use SdFat.h."));
- #else
- Serial.println(F("Using SdFat.h. Set USE_SD_H nonzero to use SD.h."));
- #endif
- Serial.println(F("\nType any character to begin."));
- while (!Serial.available()) {
- yield();
- }
- Serial.print("Initializing SD card...");
- if (!SD.begin(SD_CS_PIN)) {
- Serial.println("initialization failed!");
- return;
- }
- Serial.println("initialization done.");
-
- myFile = SD.open("test.txt", FILE_WRITE);
-
- if (myFile) {
- Serial.print("Writing to test.txt...");
- myFile.println("testing 1, 2, 3.");
-
- myFile.close();
- Serial.println("done.");
- } else {
-
- Serial.println("error opening test.txt");
- }
-
- myFile = SD.open("test.txt");
- if (myFile) {
- Serial.println("test.txt:");
-
- while (myFile.available()) {
- Serial.write(myFile.read());
- }
-
- myFile.close();
- } else {
-
- Serial.println("error opening test.txt");
- }
- }
- void loop() {
-
- }
|