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.

readlog.ino 1.2KB

10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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() {}