1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #include <SPI.h>
- #include "SdFat.h"
- #include "sdios.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) {
- SysCall::yield();
- }
-
- cout << F("Type any character to start\n");
- while (!Serial.available()) {
- SysCall::yield();
- }
- delay(400);
-
-
- if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) {
- sd.initErrorHalt();
- }
-
- logEvent("Another line for the logfile");
- cout << F("Done - check /logs/2014/Jan/logfile.txt on the SD") << endl;
- }
- void loop() {}
|