I have defined a c++ class (RpmDriver) and want to use attachInterrupt in the constructor to link an Arduino pin to its ISR (RpmInt) in the class. When I try this, I get:
error: cannot convert 'RpmDriver::RPMInt' from type 'void (RpmDriver::)()' to type 'void (*)()'
This is the cpp file:
#include "RpmDriver.h"
#include <Arduino.h>
int currentRpm;
long lastMillis;
int pin;
RpmDriver::RpmDriver(int Pins[])
{
pin=Pins[0];
currentRpm=0;
pinMode(pin,INPUT);
lastMillis = millis();
attachInterrupt(digitalPinToInterrupt(pin),RPMInt, RISING);
}
RpmDriver::~RpmDriver(void)
{}
bool RpmDriver::GetData(char* dest,char* format)
{
sprintf(dest,format,currentRpm);
}
void RpmDriver::RPMInt()
{
double RPMConstant=40000;
unsigned long newMillis=millis();
unsigned long t = newMillis-lastMillis;
t=100;//temp
currentRpm=(t==0)?0:(int)RPMConstant/t;
lastMillis=newMillis;
}
and the header file is
#pragma once
class RpmDriver
{
public:
RpmDriver(int pins[]);
~RpmDriver(void);
bool GetData(char*,char*);
private:
void RPMInt(void);
};
Any help much appreciated!