Hello,
I need to setup a large (100 or so pairs of ints) lookup table to connect two set of numbers that are not mathematically related, i.e. One cannot be calculated from the other.
I am plannig to set up an array like this:
If you have the hardware needed to read from an SD card, it would be relatively easy to read your data from a text file at run time. Alternatively you could store it in EEPROM, but you'd have to write a program on the PC to send the data to put there, both for the initial load and when you wanted to change it. Or you could put the initialization code in another tab in the IDE to keep it segregated from your main sketch. With this last method, you would still have to reload the sketch every time you made a change. Another way would be to use the Arduino as a web client and go get the data from a web server at startup.
questions pop up.
What do these values represent?
what is the range of values?
Can you post a part of the table?
Would it fit in a byte ?
Are there repeating patterns in the table?
Are they interpolatable?
Are you using the tabs feature of the IDE?
Put the array and your other pin mappings and global variations in one tab, called a_presetup. Be sure to use progmem for the array unless the sketch needs to change the values.
put void setup in a 2nd called b_setup
put void look in a 3rd called c_loop
seperates things nicely.
When you save, the first tab will be your sketch file name, I use that for any notes I want to keep.
Thanks for all the answers !
I was (vaguely) thinking along the lines of dhenry and crossroads' solutions. I am going to research those
I was thinking maybe I can just #include it or something.
Another thing i thought would be to create a library that does the data loading but that seems to me more trouble that it's worth, to keep the long list away from the program itself.
Thanks AWOL and Nick,
I am still baffled by the fact that in the declaration "1" means 1 total and in the assignment "1" means the second item: 0 - 1.
I keep on making this mistake and the IDE keeps on reminding me about that (I'm glad the IDE didn't get tired of that yet).
Thanks also for the PROGMEM tip and for the link! I can do it so long as the program does not need to modify it, correct?
Though it may not be necessary as an int array of 100 x 2 entries should occupy 2 x 100 x 2 = 400 bytes).
As the second numbers are not bigger than a byte I could create two monodimensional arrays, one int and one byte for a total of 100 * (2 + 1) = 300 bytes (plus some overhead, I assume).
Finally, can I put the code in a function at the end of the sketch and call it from setup(), maybe by stating somehow it's a global array or, being it a variable assignment must it go before setup() (that would make the sketch neater) ?
Thot:
I am still baffled by the fact that in the declaration "1" means 1 total and in the assignment "1" means the second item: 0 - 1.
You declare the number you want. eg.
int foo [2];
You get an array of two. However they are zero-relative. So you index into 0, 1.
Thanks also for the PROGMEM tip and for the link! I can do it so long as the program does not need to modify it, correct?
Yes.
Finally, can I put the code in a function at the end of the sketch and call it from setup(), maybe by stating somehow it's a global array or, being it a variable assignment must it go before setup() (that would make the sketch neater) ?
The assignments would take instructions. It seems much simpler to pre-assign the array (ie. declare the contents, don't assign them). Then it would need to be globally defined (or at least, static inside a function).
As the second numbers are not bigger than a byte I could create two monodimensional arrays, one int and one byte for a total of 100 * (2 + 1) = 300 bytes (plus some overhead, I assume).
You could do that, but if you keep them in program memory you have 32 Kb to play with, so you aren't running out yet.
It compiles flawlessly but the serial monitor shows nothing (should show "tizio")!
On what version of the IDE? Prior to 1.0.1, the failure of the compiler to find an include file was a fatal error. With 1.0.1, the failure to find an include file doesn't even generate a warning.
The failure to find the include file would explain the behavior you are seeing.
Eventually, my goal is to import a bidimensional array of numbers, but right now, for testing purposes I am experimenting with the following:
The entirety of "mydata.hh" contains the following text:
"tizio", "caio", "sempronio"
The entirety of "numbers.hh" contains:
1,2,3,4
"mydata.hh" on disk is 30 bytes long.
"numbers.hh"on disk is 9 bytes long.
guix:
It should work, are you sure the baud speed is the same in the serial monitor window?
Yes I made sure they are the same.
PaulS:
With 1.0.1, the failure to find an include file doesn't even generate a warning.
The failure to find the include file would explain the behavior you are seeing.
I am using 1.0.1
If I don't put the whole path, the compilers gives me an error: "No such file or directory".