Go Down

Topic: Looking for a location for user-created headers (Read 1 time) previous topic - next topic

bitrex

Well, I've run into another problem now that I've got my problem with assigning pointers to elements of arrays straightened out.  I'm dealing with a couple of large arrays of numbers, and I was hoping to store them in a header file so they wouldn't clutter up the code, however when I put the header file in the sketch directory and do #include "arrays.h" the compiler can't find it.  Any ideas?

Groove

You would normally only put variables in a header if you were going to have them shared between several source files, and unless you're very careful with the declaration, you could end up with more than one instance of the variable.

I don't see how two arrays can clutter up code.
Keep it local - it avoids all kinds of potential hassle.

Per Arduino ad Astra

bitrex

Quote
I don't see how two arrays can clutter up code.


They're wavetables for direct digital synthesis - each array has 255 1 byte values, and I eventually will need 4 of them.  It's a lot of stuff to have sitting at the top of my sketch... :o

Groove

Quote
It's a lot of stuff to have sitting at the top of my sketch...


So, put them at the bottom of your sketch, with a forward extern reference at the top.   8-)
Per Arduino ad Astra

Kitep

You probably have them in the wrong directory.  Assuming you're Windows based, and the name of your library file is WaveTableArray.h

1) put the file in a folder named WaveTableArray
2) put this folder in arduino-0015\hardware\libraries\
 (or whereever your aduino files are)
  Note: this is NOT the directory in My Documents where you store the sketches)

Good luck!

Professor Chaos

Why not put them as a separate tab in the IDE?

Kitep

#6
Jul 09, 2009, 05:40 am Last Edit: Jul 09, 2009, 05:46 am by Kitep Reason: 1
I'm not familiar with tabs and a quick search didn't turn up how to use them.  Could you point me to an instruction page?  Thanks.


Never mind.  I found it: http://www.arduino.cc/en/Hacking/BuildProcess

And the relevant stuff:
Quote
Multi-file sketches
A sketch can contain multiple files (tabs). To manage them, click on the right-facing arrow just above the scroll bar near the top of the environment. Tabs have one of four extensions: no extension, .c, .cpp, or .h (if you provide any other extension, the period will be converted to an underscore). When your sketch is compiled, all tabs with no extension are concatenated together to form the "main sketch file". Tabs with .c or .cpp extensions are compiled separately. To use tabs with a .h extension, you need to #include it (using "double quotes" not <angle brackets>).




bitrex

#7
Jul 17, 2009, 08:02 am Last Edit: Jul 17, 2009, 08:19 am by bitrex Reason: 1
Sorry for the delay in my reply, I had been on vacation for a while.  I've come back to this problem, and unfortunately I still can't get adding files to the sketch to work.  Putting it in my libraries folder as a .h file doesn't work (no such file or directory), and when I select "Add File" from the Sketch menu and select the file I want to add, no tab is added - nothing happens at all.  Any ideas?  

Edit: I have it working now, I found the little arrow button at the far right of the environment (couldn't see it hiding over there!) and created a tab, then pasted in my data.  Unfortunately, I've hit another problem, in that when I declare arrays or variables in this new tab the main sketch file doesn't "see" them when it compiles and I keep getting "not declared in this scope" errors.

Edit again: If I declare the arrays in both the main program and the tab, I get a variable redefinition error...if I declare the arrays just at the top of the main program, everything compiles fine. So it seems like maybe there's some kind of ordering issue with the compiler where it's looking at the main program first and causing an error when it hasn't yet looked at the tab where the variables are defined?  :-?

Kitep

You have to manually erase the .o file before compiling, or the library won't be recompiled.

Go Up