monkeyboard / Wiegand-Protocol-Library-for-Arduino

Wiegand 26 and Wiegand 34 Protocol Library for Arduino
323 stars 131 forks source link

Feature Request - Pin Change Interrupt Support #46

Open zacaustin opened 4 years ago

zacaustin commented 4 years ago

I was wondering if it would be possible to add Pin Change Interrupt support to this library to enable a Wiegand reader to be connected to another pair of pins on the board?

Currently working on a project where I need to use the Pins 2 and 3 on an Arduino Uno for other purposes but can't use a Mega to get additional Hardware Interrupt Pins.

I would have a go myself but I'm not quite at the skill level to implement this.

fjld93 commented 3 years ago

Hi, the quick solution that I used was use the PinChangeInterrupt library by Nico Hood, and then, change the "private" to "protected" in the header file, in this way, we can use the variables in a derivated class.

After that, i made a derivated class and just overload the begin method, just like:

`#include

include

include

include

include

class WiegandPCINT : public WIEGAND {

public: void begin(int pinD0, int pinD1){ _lastWiegand = 0; _cardTempHigh = 0; _cardTemp = 0; _code = 0; _wiegandType = 0; _bitCount = 0;
pinMode(pinD0, INPUT); // Set D0 pin as input pinMode(pinD1, INPUT); // Set D1 pin as input

attachPinChangeInterrupt(digitalPinToPinChangeInterrupt(pinD0), ReadD0, FALLING);
attachPinChangeInterrupt(digitalPinToPinChangeInterrupt(pinD1), ReadD1, FALLING);

}

};`

With this changes, you can use any pin that allow PCINT. Note that PinD0 is the pin that will receive the "0" bits, and PinD1 will receive the "1" bits.

Regards.

jpliew commented 3 years ago

Please take a look at this

https://github.com/jpliew/Multi-Reader-Wiegand-Protocol-Library-for-Arduino