#include /* * RFID Loop w/LCD Display and Piezo Sounder * by Alexander Reeder, Nov 16, 2007 * Modified by Brian Riley January 27, 2008 * Modified for Display and audible * Brian Riley January 28, 2008 */ #define LCDpin 14 #define RESETLEDPin 13 #define RESETPIN 2 #define MISSES 5000 SWSerialLCDPHA mySerial = SWSerialLCDPHA(LCDpin); char val = 0; int misscount = MISSES; void setup() { pinMode(LCDpin, OUTPUT); // define pin modes for tx pin Serial.begin(9600); // initialize UART mySerial.begin(19200); // set the data rate for the SoftwareSerial port mySerial.clearscr(); // gets the SW Serial pump flowing mySerial.clearscr(); // cleans screen after whatever goop comes from startup mySerial.setgeo(216); // set chip geometry for a 2x16 display mySerial.setintensity(0x80); // set backlight at mx intensity pinMode(RESETPIN, OUTPUT); // sets the digital pin as output pinMode(RESETLEDPin, OUTPUT); // sets the digital pin as output misscount = 0; } void loop () { char IDstring[13]; int i; digitalWrite(RESETLEDPin, LOW); // Shut off LED digitalWrite(RESETPIN, HIGH); // pull up Reset line if (Serial.available() > 0 ) { if ( (val = Serial.read()) == 02 ) { // look for Start Of Text marker // read until you get End Of Text for ( i = 0; (val = Serial.read()) != 03 ; i++) { IDstring[i] = val; Serial.print(val, HEX); Serial.print(" "); } Serial.println(); IDstring[10] = 0x00; // tie off IDstring at the CR-LF mySerial.print("?f ID=["); mySerial.print(IDstring); mySerial.print("]"); resetID12(); // reset after a valid read misscount = MISSES; } } else { // basically this code lets you see the ID for about 5 seconds then // replaces ID display with "waiting," 5000 1 ms loops, so if a new // ID card is presented it chnages immediately to new ID display. if (misscount-- == 0) { mySerial.print("?f ... waiting ..."); } delay(1); } } void resetID12() { digitalWrite(RESETLEDPin, HIGH); // show reset by lighting LED digitalWrite(RESETPIN, LOW); // pull reset down delay(100); // hold reset for 100 ms }