Hi guys,
I would like to use a timer within a class.
I started trying to include TimerOne.h to my class header and then using Timer1.
MyClass.h:
#ifndef MYCLASS_H
#define MYCLASS_H
#include "TimerOne.h"
class MyClass {
/* ATTRIBUTES */
private:
static MyClass *_instance;
/* FUNCTIONS */
public:
MyClass(int useless);
~MyClass() {
}
private:
static void myIsr(void);
};
#endif /* MYCLASS_H */
MyClass.cpp:
#include "MyClass.h"
MyClass* MyClass::_instance; // Instantiate the static pointer
MyClass::MyClass(int useless) {
_instance = this;
Timer1.initialize(5000000);
Timer1.attachInterrupt(myIsr);
}
void MyClass::myIsr(void) {
Serial.println("Should be printed every 5s...");
}
myClass.ino:
#include <MyClass.h>
MyClass myObj(0);
void setup() {
Serial.begin(9600);
}
void loop() {
}
The code compiles without any complaint.
During execution the message is printed on the screen but with a period (visibly) less than 5 s!
Trying to change the period seems not to have any effect.
What's wrong with that code?
Thank you in advance for your collaboration.
Regards,
Marco