I searched online without success. Found 100 of results, but not the solution.
I want to read the content of 35 external text files in my code and have them compiled when the code is being compiled.
The content of one text file is an array:
const int16_t EXAMPLE[] = {a huge amount number};
For now, the content of these 35 text files is paste in the code by hand, then compiled. But this is a painful solution, cause I’d like to be able to choose 35 files out of 2000 and try different combinations so to say.
Having them externally would allow me (and others) to simply drop 35 files which were chosen into a directory, rename them from 0 to 34 and read them in the code, compile. Done.
Of course it would be smarter to have a SD Card with all files insides and read them while the code is executing, but it can’t be done here in this project, because there’s no way a SD card can be added to the hardware which already exists and all pins are also taken anyway. I only want to simplify the process of rying different combinations.
So I need to be able in my .ino file to add a script picking the content on each text file, one by one (like going through an array).
I have a directory myDirectory with my .h and .ino files inside.
I’d then add my 35 files (like „0.txt“, „1.txt“ etc) into myDirectory or another directory inside myDirectory and read them into the code.
So instead of having all my huge arrays of numbers paste by hand in my .ino file, I’d have in my .ino file something like (oversimplified):
myArray1 = the array in my text file 0.txt
myArray2 = the array in my text file 1.txt
which I’d try later to put in a loop instead, so no need to write 35 lines, but only one. Something I’d do in php like this and that I’ll will learn to do in C.
for ($n = 0; $n <= 34; $n++) {
„myArray“+n = n+“.txt“
}
To simplify for now, it means I first need to know if it’s possible to say in the code to go and look for a file named „0.txt“ in a directory called „whatever“ and read it’s content, without the use of a SD file. No runtime here. I only want add dynamic content to my code to be compiled.
More info:
I searched online but couldn’t find an answer. On this forum I search for +read text file“, there are a lot of results, but I don’t see the solution:
Read set up text file at compile - Programming Questions - Arduino Forum
How to import a txt file to arduino ? - Programming Questions - Arduino Forum
Reading data from a Text file - Programming Questions - Arduino Forum
Reading Text Files - Syntax & Programs - Arduino Forum
They seem to refer to the arduino chip reading the file via serial.
I did read this
SD - Arduino Reference
But what I am asking is how I can read the content of a text file BEFORE compiling.
It’s not about reading a file from a SD Card while the compiled code is executing on an Arduino hardware. And as mentionned, no pin on the hardware is free anymore