Esta es la continuacion del post de arriba este es lo del rfid:
#define NumberOfKeys 10 //This defines the amount of keys in the access list
#define WAIT_TIME 2000 //Time door will remain open
#define BLINKS 3 //The amount of times the indicators blink when blinking is required
#define ON_TIME 200 //time in milliseconds the relay stays energized
const int TxPin = 7; //FOR PARALLAX SERIAL LCD and we use rx in the arduino for SEROUT from RFID module
#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin); //FOR SERIAL LCD
//External Equipment
#define ENABLE 2 //Pin connected to the Enable pin of RFID parallax
#define LOCK 9 //Pin that is connected to NPN transistor that energizes lock
//LED Indicators
#define OPEN_LIGHT 11 //LED indicator. Indicates the correct key was entered
#define DENIED_LIGHT 12 //LED indicator. Indicates the wrong key was entered
#define PROGRAMMING_LIGHT 13 //LED indicator. Indicates Programming mode is activated
int val = 0;
int bytesread = 0;
String Master = "123456789"; //"PERSONAL RFID CARD NUMBER"
String empty = "0000000000";
String keyCode;
String accessList[NumberOfKeys];
char code[10];
boolean programmingMode,isInAccessList,KeyFound = false;
void setup() {
pinMode(OPEN_LIGHT,OUTPUT);
pinMode(DENIED_LIGHT,OUTPUT);
pinMode(PROGRAMMING_LIGHT,OUTPUT);
pinMode(ENABLE,OUTPUT);
pinMode(LOCK,OUTPUT);
//Generates an array of size corresponding to the size of the access list
for(int i = 0;i<NumberOfKeys;i++){
accessList = empty;
}
Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
digitalWrite(OPEN_LIGHT,LOW);
digitalWrite(DENIED_LIGHT,LOW);
digitalWrite(PROGRAMMING_LIGHT,LOW);
digitalWrite(ENABLE, LOW); // LOW Activates the RFID reader, HIGH deactivates it
digitalWrite(LOCK,LOW);
pinMode(TxPin, OUTPUT);
digitalWrite(TxPin, HIGH);
/////////////////////////////FOR PARALLAX SERIAL LCD ///////////////////////////////////////
-
mySerial.begin(9600);*
-
delay(100);*
-
mySerial.write(12); // Clear *
-
mySerial.write(17); // Turn backlight on*
-
delay(5); // Required delay*
mySerial.print("CHECKING SYSTEM"); // First line
-
mySerial.write(13); //LET'S GO THE NEXT LINE*
-
mySerial.print(" CALIBRATING"); //SECOND LINE*
-
mySerial.write(212); // Quarter note*
-
mySerial.write(220); // A tone*
-
delay(3000); //LET'S WAIT FOR THE MESSAGE ON THE LCD DISPLAY*
-
mySerial.write(12); //LET'S CLEAN UP THE DISPLAY*
mySerial.write(18); //LET'S TURN OFF THE LCD BACKLIGHT
delay(5); //REQUIRES THIS DELAY
} *
void loop() {
_ /*** EXTRACTION OF DATA FROM CARD ****/_
-
if(Serial.available() > 0) { // if data available from reader*
-
if((val = Serial.read()) == 10) { // check for header [Header of data = 10]*
-
bytesread = 0;*
-
while(bytesread<10) { // read 10 digit code*
-
if( Serial.available() > 0) {*
-
val = Serial.read();*
-
if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading*
-
break; // stop reading*
-
}*
-
code[bytesread] = val; // add the digit*
-
bytesread++; // ready to read next digit*
-
}*
-
}*
-
if(bytesread == 10) { // if 10 digit read is complete*
-
digitalWrite(ENABLE, HIGH); // deactivate the RFID reader for a moment so it will not flood*
-
keyCode = code;*
-
keyCode = keyCode.substring(0,10);*
_ /*** INTERPRETATION OF DATA ***/_
-
//At this point, data was read, and there is a keycode in the keyCode variable *
-
if((keyCode == Master) && (programmingMode == false))*
-
{programmingMode = true;*
-
digitalWrite(PROGRAMMING_LIGHT,HIGH);*
-
mySerial.print(" SETUP READY");*
-
mySerial.write(13);*
-
mySerial.print(" ADD OR DELETE");*
-
mySerial.write(17);*
}
-
else*
-
{if(programmingMode == false)*
-
{*
-
for(int i = 0;i<NumberOfKeys;i++) //check entered key against saved keys*
-
{*
_ if(keyCode.equals(accessList*)){_
_ KeyFound = true;} //if the key is in the access list, KeyFound = true;_
_ }_
_ if(KeyFound)_
_ {_
_ accessGranted();_
_ KeyFound = false;_
_ }_
_ else{_
_ accessDenied();*_
* }*
* }*
* else if(programmingMode)*
* {*
* if(keyCode.equals(Master)){ //Master Key swipped during programming mode*
* }else*
* {*
* isInAccessList = false; //this is an initialization value, if the key is in the access list, this variable will be true later. *
* for(int i = 0;i< NumberOfKeys;i++) //Scans Access List*
_ {if(keyCode.equals(accessList*)) //if the card read is in the Access List*
* {
accessList = empty; //delete it
isInAccessList = true; //isInAccessList set to true, meaning the key was in the access list*
* keyDeleted();
mySerial.print(" A CARD JUST ");
mySerial.write(13);
mySerial.print(" BEEN DELETED");
mySerial.write(17);
}
}
if(isInAccessList == false) //if the key swipped is not in the access list and...
{
for(int i = 0;i< NumberOfKeys;i++){
if(accessList.equals(empty)) //...if current Access List Slot is Empty*
{accessList = keyCode; //Enter Key into Access List Slot
* newKeyEntered();
mySerial.print(" A CARD JUST ");
mySerial.write(13);
mySerial.print(" BEEN ADDED");
mySerial.write(17);
break;
}
if(i == (NumberOfKeys - 1)) //if you get to this point at last interation of loop, access List is full*
* listFull();
}
}
}*_
* digitalWrite(PROGRAMMING_LIGHT,LOW);*
* programmingMode = false; //Programming is done, turn programming mode and indicator off*
* }*
* }*
* resetIndicators();*
* } //end of data reading*
* }*
}
}
/*** CLEARS DATA FROM BUFFERS TO AVOID DOUBLE READS***/
void flushBuffers(){
* while(Serial.available() > 0) //if there is still data remaining in the RFID reader buffer*
* Serial.read(); //read it into arduino buffer*
* Serial.flush(); //then flush it*
}
/*** RESETTING INDICATORS ***/
void resetIndicators(){
* delay(WAIT_TIME); //wait a little*
* flushBuffers(); //clear buffers*
* digitalWrite(LOCK,LOW); //return everything to starting position*
* digitalWrite(OPEN_LIGHT,LOW);
digitalWrite(DENIED_LIGHT,LOW);
_ digitalWrite(ENABLE,LOW);
mySerial.write(12);
mySerial.write(18);
}*_