Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

46 lines
1.4KB

  1. // An example of the SdFatSoftSpi template class.
  2. // This example is for an Adafruit Data Logging Shield on a Mega.
  3. // Software SPI is required on Mega since this shield connects to pins 10-13.
  4. // This example will also run on an Uno and other boards using software SPI.
  5. //
  6. #include <SPI.h>
  7. #include <SdFat.h>
  8. #if USE_MULTIPLE_SPI_TYPES // Must be nonzero in SdFat/SdFatConfig.h
  9. //
  10. // Pin numbers in templates must be constants.
  11. const uint8_t SOFT_MISO_PIN = 12;
  12. const uint8_t SOFT_MOSI_PIN = 11;
  13. const uint8_t SOFT_SCK_PIN = 13;
  14. //
  15. // Chip select may be constant or RAM variable.
  16. const uint8_t SD_CHIP_SELECT_PIN = 10;
  17. // SdFat software SPI template
  18. SdFatSoftSpi<SOFT_MISO_PIN, SOFT_MOSI_PIN, SOFT_SCK_PIN> sd;
  19. // Test file.
  20. SdFile file;
  21. void setup() {
  22. Serial.begin(9600);
  23. while (!Serial) {} // Wait for Leonardo
  24. Serial.println("Type any character to start");
  25. while (Serial.read() <= 0) {}
  26. if (!sd.begin(SD_CHIP_SELECT_PIN)) sd.initErrorHalt();
  27. if (!file.open("SOFT_SPI.TXT", O_CREAT | O_RDWR)) {
  28. sd.errorHalt(F("open failed"));
  29. }
  30. file.println(F("This line was printed using software SPI."));
  31. file.close();
  32. Serial.println(F("Done."));
  33. }
  34. //------------------------------------------------------------------------------
  35. void loop() {}
  36. #else // USE_MULTIPLE_SPI_TYPES
  37. #error USE_MULTIPLE_SPI_TYPES must be set nonzero in SdFat/SdFatConfig.h
  38. #endif //USE_MULTIPLE_SPI_TYPES