Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - Pin Change Interrupt Support #46

Open
zacaustin opened this issue Feb 11, 2020 · 2 comments
Open

Feature Request - Pin Change Interrupt Support #46

zacaustin opened this issue Feb 11, 2020 · 2 comments

Comments

@zacaustin
Copy link

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
Copy link

fjld93 commented Sep 15, 2020

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 <Wiegand.h>

#include <PinChangeInterrupt.h>
#include <PinChangeInterruptBoards.h>
#include <PinChangeInterruptPins.h>
#include <PinChangeInterruptSettings.h>

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
Copy link
Collaborator

jpliew commented Feb 15, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants