Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <SPI.h>
- #include <SdFat.h>
- #define SD_CS_PIN 3
- #define LEDPIN 4
- SdFat SD;
- File dataFile;
- void setup()
- {
- pinMode(LEDPIN, OUTPUT);
- // Open serial communications and wait for port to open:
- Serial.begin(9600);
- digitalWrite(LEDPIN, HIGH);
- Serial.print("\nInitializing SD card...");
- if (!SD.begin(SD_CS_PIN))
- {
- Serial.println(" failed!");
- return;
- }
- else
- {
- Serial.println(" done!");
- }
- String fileName;
- fileName = "GPSData_";
- fileName += String("02");
- fileName += String("01");
- fileName += String("2024");
- fileName += String("_");
- fileName += String("15");
- fileName += String("10");
- fileName += String("00");
- fileName += String(".kml");
- Serial.print("File name is: ");
- Serial.println(fileName);
- // open the file. note that only one file can be open at a time,
- // so you have to close this one before opening another.
- // (O_READ | O_WRITE | O_CREAT) erases any previous content and then writes.
- // FILE_WRITE is (O_RDWR | O_CREAT | O_AT_END)
- dataFile = SD.open(fileName, FILE_WRITE);
- // if the file opened okay, write to it:
- if (dataFile)
- {
- Serial.print("Writing to file...");
- dataFile.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- dataFile.println("<kml xmlns=\"http://www.opengis.net/kml/2.2\">");
- dataFile.println("");
- dataFile.println(" <Document>");
- dataFile.println(" <name>Views with Time</name>");
- dataFile.println(" <open>1</open>");
- dataFile.println(" <description>");
- dataFile.println(" In Google Earth 20, enable historical imagery and sunlight,");
- dataFile.println(" then click on each placemark to fly to that point in time.");
- dataFile.println(" </description>");
- dataFile.println("");
- dataFile.println(" <Placemark>");
- dataFile.println(" <name>Sutro Baths in 1946</name>");
- dataFile.println(" <gx:TimeStamp>");
- dataFile.println(" <when>1946-07-29T05:00:00-08:00</when>");
- dataFile.println(" </gx:TimeStamp>");
- dataFile.println(" <longitude>-122.518172</longitude>");
- dataFile.println(" <latitude>37.778036</latitude>");
- dataFile.println(" <altitude>221.0</altitude>");
- dataFile.println(" </Placemark>");
- dataFile.println("");
- dataFile.println(" </Document>");
- dataFile.println("</kml>");
- dataFile.close();
- Serial.println(" done!");
- }
- else
- {
- // if the file didn't open, print an error:
- Serial.println("Error opening file for writing!!");
- }
- // re-open the file for reading:
- Serial.print("\n\nReading from file: ");
- Serial.println(fileName);
- Serial.println("");
- dataFile = SD.open(fileName, FILE_READ);
- if (dataFile)
- {
- // read from the file until there's nothing else in it:
- while (dataFile.available())
- {
- Serial.write(dataFile.read());
- }
- // close the file:
- dataFile.close();
- Serial.println("\n File read!");
- }
- else
- {
- // if the file didn't open, print an error:
- Serial.println("Error opening file for reading!!");
- }
- Serial.end();
- }
- void loop()
- {
- // nothing happens after setup
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement