Chat freely about anything...

User avatar
By tomjuggler
#88437 So for reading a .csv file I'm using:

Code: Select allf = LittleFS.open("/f.txt", "r");
while (f.available()) {
      String X = f.readStringUntil(',');
      int Y = X.toInt();
//    do stuff with Y - pixel information for LED Array
}
f.close();     


The f.open() function seems to take a bit of time. My question is, how to read continuously values from the same file without closing and re-opening it again every time? Also, is a .csv file the best way to store an array of bytes in LittleFS?

My current approach is to load the entire .csv into an array stored in RAM, however 64K doesn't go very far.
User avatar
By btidey
#88456 You can just store the bytes in the file raw.

file.readbytes(buffer, length) will read length bytes from the file and store it into a buffer.

Similarly file.write(buffer, length) will write length bytes from a buffer to a file open for writing.

If you are writing to a screen then you might consider reading in smaller chunks into a buffer before writing to the screen to conserve memory, but if the screen is already buffered then you might as well readbyes directly into that.