I am aware there are issues trying to put an interrupt routine inside a class and there are workarounds for that. In the following code, I tried to use a workaround but there appears to be something wrong with the way the pointers are defined.
Can someone help me understand what I am doing wrong?
The error:
TimerPointer.cpp:14:5: error: no match for call to '(TeensyTimerTool::PeriodicTimer) (void (*&)(), int)
TimerPointer.ino:
#include "TeensyTimerTool.h"
#include "TimerPointer.h"
using namespace TeensyTimerTool;
TestClass tc;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
tc.begin();
}
void loop() {
}
void callback() // switch off LED
{
digitalWriteFast(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
TimerPointer.cpp:
#include "TimerPointer.h"
#include "Arduino.h"
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;
PeriodicTimer t1(GPT1);
typedef void (*functPtr)();
TestClass::TestClass(){};
void TestClass::begin() {
functPtr myPtr = myInterrupt;
t1(myPtr, 500000);
}
void TestClass::myInterrupt() {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
TimerPointer.h:
#ifndef __TIMERPOINTER_H__
#define __TIMERPOINTER_H__
class TestClass {
private:
public:
TestClass();
void begin();
static void myInterrupt();
};
#endif