#include <SD.h>
void setup()
{
Serial.begin( 115200 );
SD.begin( 10 );
// Write lines to file
File file = SD.open( "data.txt", FILE_WRITE );
if ( file )
{
file.print( "\n1234" );
file.print( "\n567" );
file.print( "\n89" );
file.close();
}
// Read all lines from file
file = SD.open( "data.txt" );
if ( file )
{
while ( file.available() )
{
static char line[10];
static size_t line_index = 0;
char character = file.read();
if ( line_index < sizeof( line ) - 1 && character != '\n' )
{
line[ line_index++ ] = character;
}
if ( line_index > 0 && ( character == '\n' || !file.available() ) )
{
line[ line_index ] = '\0';
line_index = 0;
Serial.print( "\"" );
Serial.print( line );
Serial.println( "\"" );
}
}
file.close();
}
}
void loop()
{
}