No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

50 líneas
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. // 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. void setup() {
  15. int c;
  16. Serial.begin(9600);
  17. // Wait for USB Serial
  18. while (!Serial) {
  19. SysCall::yield();
  20. }
  21. // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  22. // breadboards. use SPI_FULL_SPEED for better performance.
  23. if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
  24. sd.initErrorHalt();
  25. }
  26. // set current working directory
  27. if (!sd.chdir("logs/2014/Jan/")) {
  28. sd.errorHalt("chdir failed. Did you run eventlog.ino?");
  29. }
  30. // open file in current working directory
  31. ifstream file("logfile.txt");
  32. if (!file.is_open()) {
  33. sd.errorHalt("open failed");
  34. }
  35. // copy the file to Serial
  36. while ((c = file.get()) >= 0) {
  37. cout << (char)c;
  38. }
  39. cout << "Done" << endl;
  40. }
  41. //------------------------------------------------------------------------------
  42. void loop() {}