Pages: [1]   Go Down
Author Topic: Looking for a location for user-created headers  (Read 1477 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Per Arduino ad Astra

0
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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-)
Logged

Per Arduino ad Astra

0
Offline Offline
Full Member
***
Karma: 1
Posts: 170
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 225
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Full Member
***
Karma: 1
Posts: 170
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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>).


« Last Edit: July 08, 2009, 10:46:09 pm by Kitep » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?  :-?
« Last Edit: July 17, 2009, 01:19:25 am by bitrex » Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 170
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: