Hi~ So I am still tinkering with my XY plotter type project. Since I control 2 DC motors and 2 encoders, I thought I would try making a library (class) instead of having lots of duplicate code in my sketch. I got pretty far with it but it is choking on the 'attachInterrupt' call:
RP_Motor.cpp: In member function 'void RP_Motor::initMotor(int, int, int, int, int, int, int, int)':
RP_Motor.cpp:61: error: argument of type 'void (RP_Motor::)()' does not match 'void (*)()'
This is line 61: attachInterrupt(interruptPin, doEncoder, CHANGE);
There is a function named 'doEncoder' in the class. If I comment out that line, the library compiles and I can control the motors but I am not getting any encoder data (since there are no interrupts).
I tried copying parts of the Wiring Encoder lib: the extern references mainly, but the compiler complainer about duplicate declarations. I do #include <avr/interrupt.h> but that doesn't work.
I suppose I can do something stupid like have the ISRs in my sketch and have them call the class instances but...
tx for any tips! Library/classes are pretty easy and fun (until I trip over something like this ![]()
--Roy