The following is a small section of a sketch that works to read the first two characters from the SD Card and put them into a new variable that will determine the size of the array to hold data. The example below uses “22” which is unclear whether it worked properly. A test with another file with 14 at the front indicated that it was able to function correctly. Note that it may fail if the number of initial digits is not two. The OpenOffice file used for issuing the
times.csv file is set up so that the figure used includes two leading zeros in the format. This will ensure the right number of digits are available.
This snippet is successfully used in this sketch and ultimately this sketch.
File dataFile = SD.open("timesfic.csv"); // In order to correctly size the array the first two digits // off the file will be read as the Number of Fields to use. char ch = dataFile.read(); // Read the first entry - tens int NoF = 10 * (ch-'0'); //Change ASCII digit to a tens digit ch = dataFile.read(); // Read the second entry NoF = NoF + ch-'0'; // Add the ones digit to the tens digit ch = dataFile.read(); // read the next figure which will be a comma, but ignore it. unsigned long values[NoF]; //This is the array to hold the values. Serial.println(NoF); ...and so on...
Initializing SD card...card initialized. 22