#include <SD.h>
#define CS_PIN 8
File f;
void setup() {
Serial.begin(9600);
if ( SD.begin( CS_PIN ) ) {
Serial.println("Card OK!");
} else {
Serial.println("No card!");
while ( true ) ; // безкінечний цикл
}
// зчитуємо з файла
f = SD.open("myfile.txt");
if ( f ) {
Serial.println("File is opened");
Serial.println( f.name() );
Serial.println( f.size() );
while ( f.available() ) {
char c = f.read(); // прочитати наступний байт інформації
Serial.print( c );
}
}
f.close(); // закрити файл
// записуємо у файл
f = SD.open("myfile.txt", FILE_WRITE);
if ( f ) {
Serial.println("File is opened for write");
f.println("New line");
}
f.close();
f = SD.open("myfile.txt");
if ( f ) {
while ( f.available() ) {
char c = f.read(); // прочитати наступний байт інформації
Serial.print( c );
}
}
f.close(); // закрити файл
}
void loop() {
// put your main code here, to run repeatedly:
}