Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

91 lines
1.8KB

  1. /*
  2. SD card basic file example
  3. This example shows how to create and destroy an SD card file
  4. The circuit:
  5. * SD card attached to SPI bus as follows:
  6. ** MOSI - pin 11
  7. ** MISO - pin 12
  8. ** CLK - pin 13
  9. ** CS - pin 4
  10. created Nov 2010
  11. by David A. Mellis
  12. modified 9 Apr 2012
  13. by Tom Igoe
  14. This example code is in the public domain.
  15. */
  16. #include <SD.h>
  17. #include <SPI.h>
  18. File myFile;
  19. // change this to match your SD shield or module;
  20. // Arduino Ethernet shield: pin 4
  21. // Adafruit SD shields and modules: pin 10
  22. // Sparkfun SD shield: pin 8
  23. // Teensy audio board: pin 10
  24. // Wiz820+SD board: pin 4
  25. // Teensy 2.0: pin 0
  26. // Teensy++ 2.0: pin 20
  27. const int chipSelect = 4;
  28. void setup()
  29. {
  30. // Open serial communications and wait for port to open:
  31. Serial.begin(9600);
  32. while (!Serial) {
  33. ; // wait for serial port to connect. Needed for Leonardo only
  34. }
  35. Serial.print("Initializing SD card...");
  36. if (!SD.begin(chipSelect)) {
  37. Serial.println("initialization failed!");
  38. return;
  39. }
  40. Serial.println("initialization done.");
  41. if (SD.exists("example.txt")) {
  42. Serial.println("example.txt exists.");
  43. }
  44. else {
  45. Serial.println("example.txt doesn't exist.");
  46. }
  47. // open a new file and immediately close it:
  48. Serial.println("Creating example.txt...");
  49. myFile = SD.open("example.txt", FILE_WRITE);
  50. myFile.close();
  51. // Check to see if the file exists:
  52. if (SD.exists("example.txt")) {
  53. Serial.println("example.txt exists.");
  54. }
  55. else {
  56. Serial.println("example.txt doesn't exist.");
  57. }
  58. // delete the file:
  59. Serial.println("Removing example.txt...");
  60. SD.remove("example.txt");
  61. if (SD.exists("example.txt")){
  62. Serial.println("example.txt exists.");
  63. }
  64. else {
  65. Serial.println("example.txt doesn't exist.");
  66. }
  67. }
  68. void loop()
  69. {
  70. // nothing happens after setup finishes.
  71. }