I am having troubles creating a collection of functions to be used in Arduino sketches and libraries. What I want is not a class, but simply a group of functions which do not require an object to be called; general utilities that can be helpful in any Arduino sketch, like an average of analog reads, or a little statistical tool.
Suppose I write a file called Utilities.h (I am not sure .h is the right extension to use in this case):
Utilities.h
#ifndef Utilities_h
#define Utilities_h
#include <Arduino.h>
void utility1(...){
...
}
float utility2(...){
...
}
//and so on
#endif
I then save this file in ../Arduino/libraries/Utilities
. Whenever I want to use my utilities from this file directly in a sketch I type #include
the full path to the file (#include <Utilities.h>
won't work).
The real problem is if I want to use this collection of functions in a library, like in the following example.
myClass.h
#ifndef myClass_h
#define myClass_h
#include "full path to Utilities.h"
class myClass{
private:
int a;
public:
myClass();
};
#endif
myClass.cpp
#include "myClass.h"
myClass::myClass(){
a = utility2(...);
}
Whenever I try to #include <myClass.h>
in my sketches and compile, I get 'multiple definition' error messages for the functions on my Utilities.h
.
So to summarize, my question is: how can I create a collection of functions that can be used both in a sketch and in a library for Arduino?