Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

48 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 SD_SPI_CONFIGURATION >= 3 // Must be set 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)) {
  27. sd.initErrorHalt();
  28. }
  29. if (!file.open("SoftSPI.txt", O_CREAT | O_RDWR)) {
  30. sd.errorHalt(F("open failed"));
  31. }
  32. file.println(F("This line was printed using software SPI."));
  33. file.close();
  34. Serial.println(F("Done."));
  35. }
  36. //------------------------------------------------------------------------------
  37. void loop() {}
  38. #else // SD_SPI_CONFIGURATION >= 3
  39. #error SD_SPI_CONFIGURATION must be set to 3 in SdFat/SdFatConfig.h
  40. #endif //SD_SPI_CONFIGURATION >= 3