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.

41 lines
1.0KB

  1. // Simple demo of the Stream parsInt() member function.
  2. #include <SPI.h>
  3. // The next two lines replace #include <SD.h>.
  4. #include <SdFat.h>
  5. SdFat SD;
  6. // SD card chip select pin - Modify the value of csPin for your SD module.
  7. const uint8_t csPin = 10;
  8. File file;
  9. //------------------------------------------------------------------------------
  10. void setup() {
  11. Serial.begin(9600);
  12. // Wait for USB Serial.
  13. while(!Serial) {}
  14. Serial.println(F("Type any character to start"));
  15. while (!Serial.available()) {}
  16. // Initialize the SD.
  17. if (!SD.begin(csPin)) {
  18. Serial.println(F("begin error"));
  19. return;
  20. }
  21. // Create and open the file. Use flag to truncate an existing file.
  22. file = SD.open("stream.txt", O_RDWR|O_CREAT|O_TRUNC);
  23. if (!file) {
  24. Serial.println(F("open error"));
  25. return;
  26. }
  27. // Write a test number to the file.
  28. file.println("12345");
  29. // Rewind the file and read the number with parseInt().
  30. file.seek(0);
  31. int i = file.parseInt();
  32. Serial.print(F("parseInt: "));
  33. Serial.println(i);
  34. file.close();
  35. }
  36. void loop() {}