|
-
- #include <SPI.h>
- #include <SdFat.h>
-
-
- const uint8_t chipSelect = SS;
-
-
- SdFat sd;
-
-
- ArduinoOutStream cout(Serial);
-
-
- void logEvent(const char *msg) {
-
- sd.mkdir("logs/2014/Jan");
-
-
- ofstream sdlog("logs/2014/Jan/logfile.txt", ios::out | ios::app);
-
-
- sdlog << msg << endl;
-
-
- if (!sdlog) {
- sd.errorHalt("append failed");
- }
-
- sdlog.close();
- }
-
- void setup() {
- Serial.begin(9600);
- while (!Serial) {}
-
-
- cout << F("Type any character to start\n");
- while (Serial.read() <= 0) {}
- delay(400);
-
-
-
- if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
- sd.initErrorHalt();
- }
-
-
- logEvent("Another line for the logfile");
-
- cout << F("Done - check /logs/2014/Jan/logfile.txt on the SD") << endl;
- }
-
- void loop() {}
|