Hello I'm trying to write a library which I need for a project of mine. What I need is that after aI call a certain function, another function will be called some time later. In order to do this I wanted to use FlexiTimer2 which is pretty good, and I can use it in a normal arduino main, but I cannot implement it in the library I'm writing.
I'm posting a minimal (non) working example:
.h file
#ifndef StepperDriverController_h
#define StepperDriverController_h
#include <stdlib.h>
#if ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#include <wiring.h>
#endif
class StepperDriverController
{
public:
StepperDriverController(unsigned char step, unsigned char direction);
void setPulseWidth(unsigned short width);
// other methods
protected:
void stepPinDown();
void step();
private:
unsigned char _pins[2];
// other attributes
};
#endif
.cpp file
#include "StepperDriverController.h"
void StepperDriverController::stepPinDown()
{
digitalWrite(_pins[0], LOW);
FlexiTimer2::stop();
}
void StepperDriverController::setPulseWidth(unsigned short width)
{
_pulseWidth = width;
FlexiTimer2::set(width, 1.0/1000000.0, stepPinDown); //here the error
}
void StepperDriverController::step()
{
digitalWrite(_pins[1], _direction ? HIGH : LOW);
digitalWrite(_pins[0], HIGH);
FlexiTimer2::start();
}
It says: “invalid use of non-static member function” which I am not able to fix.
The point is that FlexiTimer2 wants a free function as argument and I am passing a member function. But then if it is converted to a member function it will be no longer able to access member attributes.