-
Notifications
You must be signed in to change notification settings - Fork 161
/
Files.ino
76 lines (63 loc) · 2.05 KB
/
Files.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
SD card basic file example
This example shows how to create and destroy an SD card file.
The circuit. Pin numbers reflect the default
SPI pins for Uno and Nano models:
SD card attached to SPI bus as follows:
** SDO - pin 11
** SDI - pin 12
** CLK - pin 13
** CS - depends on your SD card shield or module.
Pin 10 used here for consistency with other Arduino examples
(for MKR Zero SD: SDCARD_SS_PIN)
created Nov 2010
by David A. Mellis
modified 24 July 2020
by Tom Igoe
This example code is in the public domain.
*/
#include <SD.h>
const int chipSelect = 10;
File myFile;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// wait for Serial Monitor to connect. Needed for native USB port boards only:
while (!Serial);
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("1. is a card inserted?");
Serial.println("2. is your wiring correct?");
Serial.println("3. did you change the chipSelect pin to match your shield or module?");
Serial.println("Note: press reset button on the board and reopen this serial monitor after fixing your issue!");
while (1);
}
Serial.println("initialization done.");
if (SD.exists("example.txt")) {
Serial.println("example.txt exists.");
} else {
Serial.println("example.txt doesn't exist.");
}
// open a new file and immediately close it:
Serial.println("Creating example.txt...");
myFile = SD.open("example.txt", FILE_WRITE);
myFile.close();
// Check to see if the file exists:
if (SD.exists("example.txt")) {
Serial.println("example.txt exists.");
} else {
Serial.println("example.txt doesn't exist.");
}
// delete the file:
Serial.println("Removing example.txt...");
SD.remove("example.txt");
if (SD.exists("example.txt")) {
Serial.println("example.txt exists.");
} else {
Serial.println("example.txt doesn't exist.");
}
}
void loop() {
// nothing happens after setup finishes.
}