Im relatively new to arduinos (about 3-4 months in), and recently i was trying to combine all the random ino files i've created into my own library.
But i ran into a problem i can't seem to solve and was hoping someone could help me out, or point me in the right direction.
To facilitate help, i've posted an example of my code on the gist website at
Basically, inside the .h / .cpp i've created a class called, testTools.
and this testTools contains a method/function called cppFunction.
I want this cppFunction to be able to call a function that'll be defined in the ino file
(in the above posed code, I called the ino function to be called inoFunction - and it just serial prints that it works).
overall, the idea is, that I can change the inoFunction, which is defined in in the ino file, and testTools.cppFunction() will execute the defined inoFunction accordingly.
If i run the above posted code, i get an error message along the lines of 'inoFunction not declared in scope (which makes sense to me).
I just don't know how to program this. Hoping someone can help me out.
Probably what you want is known as a callback. You pass a function pointer from the sketch to the library via the constructor or a function. That means your library is more flexible because the user is not restricted to using a specific function name in their sketch and in fact they could create multiple instances of the class and pass a different function to each.