Skip to content

Commit

Permalink
Update example in README
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-raca authored Mar 7, 2019
1 parent 2c44183 commit c1bd59b
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ _It is hardware-agnostic_!

// These are the pins connected to the Wiegand D0 and D1 signals.
// Ensure your board supports external Interruptions on these pins
#define PIN_D0 18
#define PIN_D1 19
#define PIN_D0 2
#define PIN_D1 3

// The object that handles the wiegand protocol
Wiegand wiegand;
Expand All @@ -40,8 +40,9 @@ void setup() {

//Install listeners and initialize Wiegand reader
wiegand.onReceive(receivedData, "Card readed: ");
wiegand.onReceiveError(receivedDataError, "Card read error: ");
wiegand.onStateChange(stateChanged, "State changed: ");
wiegand.begin(WIEGAND_LENGTH_AUTO);
wiegand.begin(Wiegand::LENGTH_ANY, true);

//initialize pins as INPUT and attaches interruptions
pinMode(PIN_D0, INPUT);
Expand Down Expand Up @@ -80,7 +81,8 @@ void stateChanged(bool plugged, const char* message) {
// Instead of a message, the seconds parameter can be anything you want -- Whatever you specify on `wiegand.onReceive()`
void receivedData(uint8_t* data, uint8_t bits, const char* message) {
Serial.print(message);

Serial.print(bits);
Serial.print("bits / ");
//Print value in HEX
uint8_t bytes = (bits+7)/8;
for (int i=0; i<bytes; i++) {
Expand All @@ -89,6 +91,23 @@ void receivedData(uint8_t* data, uint8_t bits, const char* message) {
}
Serial.println();
}

// Notifies when an invalid transmission is detected
void receivedDataError(Wiegand::DataError error, uint8_t* rawData, uint8_t rawBits, const char* message) {
Serial.print(message);
Serial.print(Wiegand::DataErrorStr(error));
Serial.print(" - Raw data: ");
Serial.print(rawBits);
Serial.print("bits / ");

//Print value in HEX
uint8_t bytes = (rawBits+7)/8;
for (int i=0; i<bytes; i++) {
Serial.print(rawData[i] >> 4, 16);
Serial.print(rawData[i] & 0xF, 16);
}
Serial.println();
}
```
Expand Down

0 comments on commit c1bd59b

Please sign in to comment.