Hi there
I'm trying to build a library for a motor, which allows me to send commands through a parallel IO-interface (various pins to set HIGH or LOW which can then be interpreted by the motor-controller). So far, I did this with functions in my main ino-file. But now, since everything gets a bit bigger, I would like to clean up a bit and put everything relating to that motor in a library.
Now the problem:
the IO-interface works so far, but when set for example the DRIVE-pin to HIGH, I want this pin after a delay to go LOW again (of course I could do this by a delay(), but I hope it is understandable that I do not want this).
For this purpose, I use the library <SimpleTimer>, with which I can exactly set up to do so (well, at least in my theory
:)).
Below the code of the library I reduced to the main problem:
/* ley32cIO.h */
#ifndef LEY32CIO_h
#define LEY32CIO_h
#include "Arduino.h"
#include "SimpleTimer.h"
class ley32cIO
{
public:
ley32cIO();
void begin();
void tick();
private:
SimpleTimer *timer;
int resetDelay = 50;
void Drive(bool command);
void Drive();
void ResetDrive();
};
#endif
/* ley32cIO.cpp */
#include "Arduino.h"
#include "ley32cIO.h"
ley32cIO::ley32cIO() {
timer = new SimpleTimer;
}
void ley32cIO::begin() {
}
void ley32cIO::tick() {
}
void ley32cIO::Drive(bool command) {
/*...other commands...*/
timer->setTimeout(resetDelay, ResetDrive);
}
void ley32cIO::Drive() {
Drive(true);
}
void ley32cIO::ResetDrive() {
Drive(false);
}
When I try to run this code, I get the following error-message:
sketch\ley32cIO.cpp: In member function 'void ley32cIO::Drive(bool)':
ley32cIO.cpp:19:43: error: invalid use of non-static member function 'void ley32cIO::ResetDrive()'
timer->setTimeout(resetDelay, ResetDrive);
^
In file included from sketch\ley32cIO.cpp:4:0:
sketch\ley32cIO.h:22:10: note: declared here
void ResetDrive();
^~~~~~~~~~
exit status 1
invalid use of non-static member function 'void ley32cIO::ResetDrive()'
If I then declare the void ResetDrive to static, this error disappears. But then I get a new error which tells me, that I cannot call the DRIVE-function without object (because I'm now static):
/* ley32cIO.h */
/*...rest of .h-file...*/
static void ResetDrive();
sketch\ley32cIO.cpp: In static member function 'static void ley32cIO::ResetDrive()':
ley32cIO.cpp:27:10: error: cannot call member function 'void ley32cIO::Drive(bool)' without object
Drive(0);
^
exit status 1
cannot call member function 'void ley32cIO::Drive(bool)' without object
What do I need to change to make this work?
I would like to use SimpleTimer, because I will use this library at other places in my project and would like to always use the same library.
Hope all is clear. Many thanks in advance for any help
Cheers raymeout