wipe.ino 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Example to wipe all data from an already formatted SD.
  2. #error wipe is not supported in SdFat V2. Use bool format(print_t* pr = nullptr).
  3. #include <SPI.h>
  4. #include "SdFat.h"
  5. const int chipSelect = SS;
  6. SdFat sd;
  7. void setup() {
  8. int c;
  9. Serial.begin(9600);
  10. // Wait for USB Serial
  11. while (!Serial) {
  12. yield();
  13. }
  14. Serial.println("Type 'Y' to wipe all data.");
  15. while (!Serial.available()) {
  16. yield();
  17. }
  18. c = Serial.read();
  19. if (c != 'Y') {
  20. sd.errorHalt("Quitting, you did not type 'Y'.");
  21. }
  22. // Initialize at the highest speed supported by the board that is
  23. // not over 50 MHz. Try a lower speed if SPI errors occur.
  24. if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) {
  25. sd.initErrorHalt();
  26. }
  27. // Use wipe() for no dot progress indicator.
  28. if (!sd.wipe(&Serial)) {
  29. sd.errorHalt("Wipe failed.");
  30. }
  31. // Must reinitialize after wipe.
  32. // Initialize at the highest speed supported by the board that is
  33. // not over 50 MHz. Try a lower speed if SPI errors occur.
  34. if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) {
  35. sd.errorHalt("Second init failed.");
  36. }
  37. Serial.println("Done");
  38. }
  39. void loop() {
  40. }