hello there ,
looking @ sample sdfat fgets, there way of altering (with button attached pin 8 when goes high, pressed) show next line, example loads lines in 1 go.
many thanks,
pete
looking @ sample sdfat fgets, there way of altering (with button attached pin 8 when goes high, pressed) show next line, example loads lines in 1 go.
code: [select]
// demo of fgets function read lines file.
#include <spi.h>
#include <sdfat.h>
// sd chip select pin
const uint8_t chipselect = ss;
sdfat sd;
// print stream
arduinooutstream cout(serial);
//------------------------------------------------------------------------------
// store error strings in flash memory
#define error(s) sd.errorhalt(f(s))
//------------------------------------------------------------------------------
void demofgets() {
char line[25];
int n;
// open test file
sdfile rdfile("fgets.txt", o_read);
// check open error
if (!rdfile.isopen()) {
error("demofgets");
}
cout << endl << f(
"lines '>' end '\\n' character\n"
"lines '#' not end '\\n' character\n"
"\n");
// read lines file
while ((n = rdfile.fgets(line, sizeof(line))) > 0) {
if (line[n - 1] == '\n') {
cout << '>' << line;
} else {
cout << '#' << line << endl;
}
}
}
//------------------------------------------------------------------------------
void maketestfile() {
// create or open test file
sdfile wrfile("fgets.txt", o_write | o_creat | o_trunc);
// check open error
if (!wrfile.isopen()) {
error("maketestfile");
}
// write test file
wrfile.print(f(
"line crlf\r\n"
"line lf\n"
"long line require read\n"
"\n" // empty line
"line @ eof without nl"
));
wrfile.close();
}
//------------------------------------------------------------------------------
void setup(void) {
serial.begin(9600);
while (!serial) {} // wait leonardo
cout << f("type character start\n");
while (serial.read() <= 0) {}
delay(400); // catch due reset problem
// initialize sd card @ spi_half_speed avoid bus errors with
// breadboards. use spi_full_speed better performance.
if (!sd.begin(chipselect, spi_half_speed)) {
sd.initerrorhalt();
}
maketestfile();
demofgets();
cout << f("\ndone\n");
}
void loop(void) {}
many thanks,
pete
will offer bit of $ via paypal if can help?
Arduino Forum > Using Arduino > Storage > sdfat - fgets
arduino
Comments
Post a Comment