I have a class I am defining in a set of .h and .cpp files along with my sketch. I might make it a library eventually, but for now I have it in the same folder as my pde file. In the .h file I have this at the top...
And inside my class definition I make an instance of TimerOne like so...
TimerOne Timer1;
I get compile errors when trying to use any method in TimerOne.
"undefined reference to `TimerOne::initialize(long)'"
Am I allowed to do this? If so, can you help me with what I'm doing wrong?
I'm on a windows Vista machine, using Arduino 0021. I have successfully used the TimerOne library on its own but now that I'm organizing my code into a class defined in a .h and .cpp I'm having issues.
What gets compiled and linked? Only the sketch and any source files referenced by including headers in the main sketch.
If you have a class TimerWrapper that includes TimerOne, and a sketch that includes only TimerWrapper, the sketch and TimerWrapper will be compiled, but TimerOne will not be. Any references in TimerWrapper to functions in TimerOne will result in undefined external references, as you are seeing.
The solution, then, is to include TimerOne.h in the sketch, too.
I've now included TimerOne.h in the main sketch (as well as TimerWrapper.h and now get a class redefinition error...
In file included from sketch_jan06a.cpp:2:
C:\Program Files (x86)\Arduino\Arduino-0021\libraries\TimerOne/TimerOne.h:19: error: redefinition of 'class TimerOne'
C:\Program Files (x86)\Arduino\Arduino-0021\libraries\TimerOne\TimerOne.h:20: error: previous definition of 'class TimerOne'
If I don't include it in TimerWrapper I get an error when I try to instantiate a TimerOne object that "TimerOne does not name a type".
One thing that seems a little funny is that TimerOne does not have a constructor...I'm assuming that a default constructor is provided by the compiler or something.