Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

51 rinda
1.2KB

  1. /*
  2. * Read the logfile created by the eventlog.ino example.
  3. * Demo of pathnames and working directories
  4. */
  5. #include <SPI.h>
  6. #include "SdFat.h"
  7. #include "sdios.h"
  8. // SD chip select pin
  9. const uint8_t chipSelect = SS;
  10. // file system object
  11. SdFat sd;
  12. // define a serial output stream
  13. ArduinoOutStream cout(Serial);
  14. //------------------------------------------------------------------------------
  15. void setup() {
  16. int c;
  17. Serial.begin(9600);
  18. // Wait for USB Serial
  19. while (!Serial) {
  20. SysCall::yield();
  21. }
  22. // Initialize at the highest speed supported by the board that is
  23. // not over 50 MHz. Try a lower speed if SPI errors occur.
  24. if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) {
  25. sd.initErrorHalt();
  26. }
  27. // set current working directory
  28. if (!sd.chdir("logs/2014/Jan/")) {
  29. sd.errorHalt("chdir failed. Did you run eventlog.ino?");
  30. }
  31. // open file in current working directory
  32. ifstream file("logfile.txt");
  33. if (!file.is_open()) {
  34. sd.errorHalt("open failed");
  35. }
  36. // copy the file to Serial
  37. while ((c = file.get()) >= 0) {
  38. cout << (char)c;
  39. }
  40. cout << "Done" << endl;
  41. }
  42. //------------------------------------------------------------------------------
  43. void loop() {}