Skip to content

Using MillisTimer inside a class? #1

@hcoohb

Description

@hcoohb

Hi,
I am trying to use MillisTimer inside a class, but I can't seem to get it to work.
Is it even possible?

Here is my example code:
`#include "MillisTimer.h"

class Foo
{
public:
Foo();
void handler(MillisTimer &mt);
void begin();
void loop();

private:
MillisTimer timer2;
};

Foo::Foo(){
timer2 = MillisTimer();
}

void Foo::begin(){
timer2.setInterval(2000);
timer2.expiredHandler(handler);
timer2.setRepeats(5);
timer2.start();
}

void Foo::loop(){
timer2.run();
}

void Foo::handler(MillisTimer &mt){
Serial.println("timer2 is here");
}

Foo foo;
void setup()
{
Serial.begin(9600);
foo.begin();
}

void loop()
{
foo.loop();

}`

And I get this error from arduino:
tmp/arduino_modified_sketch_733705/MillisTimer_Example.pde: In member function 'void Foo::begin()': MillisTimer_Example:21:32: error: no matching function for call to 'MillisTimer::expiredHandler(<unresolved overloaded function type>)' timer2.expiredHandler(handler); ^ /tmp/arduino_modified_sketch_733705/MillisTimer_Example.pde:21:32: note: candidate is: In file included from /tmp/arduino_modified_sketch_733705/MillisTimer_Example.pde:1:0: /home/h/libraries/MillisTimer/MillisTimer.h:37:10: note: void MillisTimer::expiredHandler(timerEventHandler) void expiredHandler(timerEventHandler handler); ^ /home/h/libraries/MillisTimer/MillisTimer.h:37:10: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'timerEventHandler {aka void (*)(MillisTimer&)}' exit status 1 no matching function for call to 'MillisTimer::expiredHandler(<unresolved overloaded function type>)'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions