yesterday complety refactored/rewrote the PinChangeInt library. There is still a compatibilty layer so there shouldnt be any need to change existing code. The new lib is more object oriented, gives you the all the needed information in the callbacks (without the need to query static variables in the lib) and allows you have several different listeners/callbacks for/on the same pin for different states
void onPinChangePortB(uint8_t pin, uint8_t state) {
printEventInfo("PortB", pin, state);
}
struct MyPinChangeListener : public PinChangeInterrupt::Listener {
virtual void pinStateChanged(uint8_t pin, uint8_t state) {
printEventInfo("PinChangeListener", pin, state);
}
};
void testGlobalUsage() {
using namespace PinChangeInterrupt;
//global usage....all calls are equivalent
attach(onPinChangePortB, PIN, CHANGE);
attachInterrupt(PIN, onPinChangePortB, CHANGE);
registerListener(new MyPinChangeListener(), PIN, CHANGE);
}
void testStaticUsage() {
using namespace PinChangeInterrupt;
//port static....all calls are equivalent
Port::registerListener(new MyPinChangeListener(), PIN, CHANGE);
Port::registerListener(onPinChangePortB, PIN, CHANGE);
}
void testInstanceUsage() {
using namespace PinChangeInterrupt;
//port instance....all calls are equivalent
Port::instanceByPin(PIN)->registerListener(new MyPinChangeListener(), PIN, RISING);
Port::instanceByID(PORTB)->registerListener(new MyPinChangeListener(), PIN, FALLING);
i'm not realy satisfied with the testInstanceUsage yet (providing two times the PIN is somethat error prone and annoying).
let me know, if you are interested and if i should post the code...