@@ -34,35 +34,10 @@ void setup() {
3434 }
3535 Serial.println (" card initialized." );
3636
37- // open the file. note that only one file can be open at a time,
38- // so you have to close this one before opening another.
39- File csv_file = SD.open (" file.csv" );
4037
4138 CSV_Parser cp (/* format*/ " dd" , /* has_header*/ true , /* delimiter*/ ' ,' );
42-
43- if (!csv_file) {
44- Serial.println (" error opening file.csv" );
45-
46- // don't do anything more:
47- while (1 );
48- }
49-
50- // read file and supply it to csv parser
51- while (csv_file.available ()) {
52- cp << csv_file.read ();
53- }
54- csv_file.close ();
55-
56- // ensure that the last value of the file is parsed (even if the file doesn't end with '\n')
57- cp.parseLeftover ();
58-
59- // output parsed values (allows to check that the file was parsed correctly)
60- cp.print (); // assumes that "Serial.begin()" was called before (otherwise it won't work)
61-
62-
39+ cp.readSDfile (" file.csv" ); // this wouldn't work if SD.begin wasn't called before
6340
64-
65- // Getting all the values:
6641 int16_t *column_1 = (int16_t *)cp[" column_1" ];
6742 int16_t *column_2 = (int16_t *)cp[" column_2" ];
6843
@@ -78,6 +53,9 @@ void setup() {
7853 } else {
7954 Serial.println (" At least 1 of the columns was not found, something went wrong." );
8055 }
56+
57+ // output parsed values (allows to check that the file was parsed correctly)
58+ cp.print (); // assumes that "Serial.begin()" was called before (otherwise it won't work)
8159}
8260
8361void loop () {
0 commit comments