Another first time library

I wanted to add a little math object to my code. After looking at the hacking site it seemed to me that the only way to link in something like this was to create a library.

So I followed the instructions and created the .h & .cpp files saved them in the library folder with their class name. This worked, they showed up in the library list.

Then I added them to the project tabs. This copied the source files to the same folder as the original source file. This is normal?

The problem is the compiler can't find/open the .h file.

Any help would be appreciated!

thanks!

-jim lee

mapper.h


#ifndef mapper_h
#define mapper_h

class mapper {

public:
mapper(double inX1, double inX2, double inY1, double inY2);
double map(double inNum);

private:
double x1;
double x2;
double y1;
double y2;
double slope;
double yIntercept;
};

#endif

mapper .cpp


#include "mapper.h"

mapper::mapper(double inX1, double inX2, double inY1, double inY2) {

x1 = inX1;
x2 = inX2;
y1 = inY1;
y2 = inY2;
slope = (y2-y1)/(x2-x1);
yIntercept = y1 - (slope * x1);
}

double mapper::map(double inNum) {

if(inNum <= x1) return(y1);
if(inNum >= x2) return(y2);
return(slope * inNum + yIntercept);
}

having the files in your sketch directory is fine. It normally saves new files this way, cut and paste them into the libraries folder if you want it for multiple projects. ( you said they were already there. )

Library's added wont add tabs to the IDE

You need the library header included in your sketch (.pde /.ino ) file.

If you leave the .h and .cpp in the same folder as the sketch use

#include "mapper.h"

otherwise if you move them to their own folder in the Arduino/Libraries folder use

#include <mapper.h>

I got it to work. The problem was that when saving .cpp or .h files the IDE makes them into .ino files. The result being, #include <something.h> no longer works. Copying the text out and saving it as a plain text .h & .cpp files fixes the problem. But, now they are un-editable by the IDE.

There has to be something I'm missing here. Can someone point me in the right direction?

Many thanks in advance!

-jim lee

There is a bug on arduino 1.0 you do save as and it.always.saves as .imo even if you unchecked the save .imo option. The arduino IDE is not suitable for library editing. use an external editor such as winedt.

AH! Well I feel better, I'd thought I was going nuts. Thanks.

Will it put together & edit multiple file programs? I'll have to go have a look.

Thanks again!

-jim lee

jimLee:
AH! Well I feel better, I'd thought I was going nuts. Thanks.

Will it put together & edit multiple file programs? I'll have to go have a look.

Thanks again!

-jim lee

Yes Winedt edits multiple files in tabs and highlights C language syntax, has line number marked on the left. You can do a lot with it but it's not free. There should be other editors with less functions I think.

well.. I'm on a Mac so I'll need to find something else. I've not worked on this kind of stuff since codeWarrior way back at the turn of the century. I wonder what's the hot ticket now?

Maybe a shiny new arduino IDE is in the works and just about ready to release?

-jim lee

Arduino is fine for libraries, build it in your sketch directory,
Once finished move it to the library folder.

Don't use IDE to create files, just create a text file directly in the sketch folder and rename it to .cpp or .h, restart the IDE and your tab is there.

The new IDE ( if one ) will most probably be released with the non-existent Due.

Oh ok, that works. I tried to open the .cpp directly with the IDE and it wouldn't do it. Hence, I thought you couldn't edit a .cpp with the IDE. Seemed kinda' silly to me not to be able to do such a thing.

Not a perfect solution, but at least it works.

Thanks everyone!

-jim lee