Created
March 23, 2016 14:10
-
-
Save delianides/648062c5009ec5361317 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* USB Wiegand Interface Reader for Arduino Leanardo | |
* | |
* Version 1.0 Dan Julio, May 18, 2013 | |
* | |
* This code is released into the public domain. It is absolutely unwarranted and unsupported | |
* meaning it may or may not work for you and you have to deal with that. | |
* running on the computer. The firmware may also be used in a stand-alone fashion just to read | |
* 26-bit cards and display their card number. | |
* | |
* The firmware makes use of the following Arduino Libraries. It also makes use of the Leanardo's | |
* USB keyboard emulation capability. | |
* 2. Timer1 Library | |
* 3. MonkeyBoard's Wiegand arduino library (www.monkeyboard.org - | |
* https://github.com/monkeyboard/Wiegand-Protocol-Library-for-Arduino) | |
* | |
* Arduino Pin Assignment | |
* Pin 2: Weigland compatible reader Data 1 (Note 1) | |
* Pin 3: Weigland compatible reader Data 0 (Note 1) | |
* | |
* | |
* Pin 10: Active Low Button Input (Note 3) | |
* Pin 11: Active High LED Output (Note 4) | |
* | |
* Notes: | |
* - Doesn't have button functionality or saving functionality. | |
* | |
*/ | |
//#include <TimerOne.h> | |
#include <Wiegand.h> | |
#include <Adafruit_NeoPixel.h> | |
//#include <RfidDb.h> | |
// ------------- | |
// Constants | |
// ------------- | |
// The inactivity timeout specifies, in seconds, how long after a card is read and displayed on the LCD | |
// to reset the LCD display back to the "Scan Card" message. | |
//#define INACTIVITY_TIMEOUT 60 | |
// The Ticks per second defines the button debounce period and is also used evaluate the inactivity timer | |
//#define TICKS_PER_SECOND 40 | |
// ------------- | |
// Variables | |
// ------------- | |
volatile boolean DebounceTick = false; | |
boolean SecondTick = false; | |
int SecondTimerCount = 0; | |
int InactivityTimerCount = 0; | |
boolean CardRead = false; | |
boolean ValidCard = false; // Only valid if CardRead is also true | |
int NumCardBits; | |
unsigned long CardData; | |
uint16_t CardNumber; | |
// ------------- | |
// Hardware Objects | |
// ------------- | |
WIEGAND wg; | |
#define PIN 6 | |
#define NUMPIXELS 1 | |
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); | |
// ------------- | |
// Arduino Entry points | |
// ------------- | |
void setup () { | |
Serial.begin(9600); | |
// Configure the hardware | |
wg.begin(); | |
pixels.begin(); // This initializes the NeoPixel library. | |
pinMode(5, OUTPUT); | |
digitalWrite(5, HIGH); | |
SetLedOutput(false); | |
// Enable Timer1 to call an ISR for debouncing the button and as a timebase for the inactivity timer. | |
//Timer1.initialize(1000000 / TICKS_PER_SECOND); | |
//Timer1.attachInterrupt(TimerOneHandler); | |
} | |
// Note: The Wiegand library must be polled constantly in order to find the start of a transmission | |
// so we don't put any delaying activities in the main loop while we are polling for new card | |
// activity. | |
void loop () { | |
// Look for input from the card reader | |
if (wg.available()) { | |
NumCardBits = wg.getWiegandType(); | |
CardData = wg.getCode(); | |
Serial.print("Wiegand HEX = "); | |
Serial.print(CardData,HEX); | |
Serial.print(", DECIMAL = "); | |
Serial.print(CardData); | |
Serial.print(", Type W"); | |
Serial.println(NumCardBits); | |
if (NumCardBits == 26) { | |
SetLedOutput(true); | |
digitalWrite(5, LOW); | |
delay(100); | |
digitalWrite(5, HIGH); | |
} else { | |
SetLedOutput(false); | |
} | |
delay(100); | |
SetLedOutput(false); | |
} | |
} | |
// ------------- | |
// Subroutines | |
// ------------- | |
void SetLedOutput(boolean b) { | |
if (b) { | |
pixels.setPixelColor(0, pixels.Color(0,150,0)); // Moderately bright green color. | |
pixels.show(); // This sends the updated pixel color to the hardware. | |
} else { | |
pixels.setPixelColor(0, pixels.Color(150,0,0)); // Moderately bright green color. | |
pixels.show(); // This sends the updated pixel color to the hardware. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment