Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SD.h>
- #include <SPI.h>
- File test;
- int pinCS = 10;
- void setup() {
- Serial.begin(9600);
- //pinMode(pinCS, OUTPUT);
- SD.begin(pinCS);
- // SD Card Initialization
- if (SD.begin())
- {
- Serial.println("SD card is ready to use.");
- } else
- {
- Serial.println("SD card initialization failed");
- return;
- }
- // Create/Open file
- test = SD.open("test.txt", FILE_WRITE);
- // if the file opened okay, write to it:
- if (test) {
- Serial.println("Writing to file...");
- // Write to file
- test.println("Testing text 1, 2 ,3...");
- test.close(); // close the file
- Serial.println("Done.");
- }
- // if the file didn't open, print an error:
- else {
- Serial.println("error opening test.txt");
- }
- // Reading the file
- test = SD.open("test.txt");
- if (test) {
- Serial.println("Read:");
- // Reading the whole file
- while (test.available()) {
- Serial.write(test.read());
- }
- test.close();
- }
- else {
- Serial.println("error opening test.txt");
- }
- }
- void loop() {
- // put your main code here, to run repeatedly:
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement