You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 10 години
преди 8 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 8 години
преди 8 години
преди 10 години
преди 10 години
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Append a line to a file - demo of pathnames and streams
  3. */
  4. #include <SPI.h>
  5. #include "SdFat.h"
  6. #include "sdios.h"
  7. // SD chip select pin
  8. const uint8_t chipSelect = SS;
  9. // file system object
  10. SdFat sd;
  11. // define a serial output stream
  12. ArduinoOutStream cout(Serial);
  13. //------------------------------------------------------------------------------
  14. /*
  15. * Append a line to logfile.txt
  16. */
  17. void logEvent(const char *msg) {
  18. // create dir if needed
  19. sd.mkdir("logs/2014/Jan");
  20. // create or open a file for append
  21. ofstream sdlog("logs/2014/Jan/logfile.txt", ios::out | ios::app);
  22. // append a line to the file
  23. sdlog << msg << endl;
  24. // check for errors
  25. if (!sdlog) {
  26. sd.errorHalt("append failed");
  27. }
  28. sdlog.close();
  29. }
  30. //------------------------------------------------------------------------------
  31. void setup() {
  32. Serial.begin(9600);
  33. // Wait for USB Serial
  34. while (!Serial) {
  35. SysCall::yield();
  36. }
  37. // F() stores strings in flash to save RAM
  38. cout << F("Type any character to start\n");
  39. while (!Serial.available()) {
  40. SysCall::yield();
  41. }
  42. delay(400); // catch Due reset problem
  43. // Initialize at the highest speed supported by the board that is
  44. // not over 50 MHz. Try a lower speed if SPI errors occur.
  45. if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) {
  46. sd.initErrorHalt();
  47. }
  48. // append a line to the logfile
  49. logEvent("Another line for the logfile");
  50. cout << F("Done - check /logs/2014/Jan/logfile.txt on the SD") << endl;
  51. }
  52. //------------------------------------------------------------------------------
  53. void loop() {}