Hi, I'm writing a little library to process interrupts from a hall probe to work out the RPM of wheel.
The code was working just fine in a sketch, but won't work (i.e. won't compile) when I move it to a library.
Heres the relevant snippet from the .cpp library file...
/**************************************************************************
Set the pin that the probe is connected to.
**************************************************************************/
void HallPulseCounter::begin(int pin)
{
int interrupt =0;
switch (pin)
{
case 2:
interrupt = 0;
break;
case 3:
interrupt = 1;
break;
case 21:
interrupt = 2;
break;
case 20:
interrupt = 3;
break;
case 19:
interrupt = 4;
break;
case 18:
interrupt = 5;
break;
default:
Serial.print("error HallPulseCounter::begin - invalid pin");
break;
}
// define the pin as an INPUT
pinMode(pin, INPUT);
// attach the appropriate interrupt
attachInterrupt(interrupt,recPulse,FALLING);
// Clear the array
arrayZeroUnsignedLong(_pulse,HALL_ARRAY_SIZE);
}
/**************************************************************************
Record the moment that a pulse was detected by the hall probe
**************************************************************************/
void HallPulseCounter::recPulse()
{
// Shift the array of values one step sideways. This will discard _pulse[HALL_ARRAY_SIZE] and
// reset _pulse[0] to zero.
arrayShiftUnsignedLong(_pulse,HALL_ARRAY_SIZE);
// Load the timestamp for this pulse into the top of the array.
_pulse[0] = millis();
}
Here's the sketch....
#include <stdlib.h> // needed for 'free'
#include "WProgram.h" // needed for 'Serial'
#include <Wire.h> // Library to control I2C comunications
#include <avr/pgmspace.h> // Needed for PROGMAN stuff
#include <ProgmemConst.h> // Global progmem constants
#include <HallPulseCounter.h> // Combined altitude library based on both pressure and ultrasonic values.
int rpm = 0;
HallPulseCounter cadence1;
void setup()
{
Serial.begin(115200); // start serial communication at 9600bps
Serial.println("##################################################################");
Serial.println("#################### START ###############################");
Serial.println("##################################################################");
cadence1.begin(2); // Connect hall sensor to pin 2
}
void loop()
{
rpm=cadence1.getFreq();
Serial.print("rpm <"); Serial.print(rpm); Serial.println("> (cm)");
delay(500); // wait for half a second
}
And this is the (only) error I get when I compile....
In member function 'void HallPulseCounter::begin(int)':
error: argument of type 'void (HallPulseCounter::)()' does not match 'void (*)()'
If I comment out this line...
attachInterrupt(interrupt,recPulse,FALLING);
then the code compiles just fine.