Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int val = 0;
- char code[10];
- String A[2],ccheck,pick;
- int bytesread = 0;
- int led0 = 13, led1=8;
- int i=0,u=0,o=0,error[2];
- void setup() {
- Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
- pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
- digitalWrite(2, LOW); // Activate the RFID reader
- pinMode(led0,OUTPUT);
- pinMode(led1,OUTPUT);
- int t1=0,emax=2;
- A[0] = String("17007C9B2B");
- A[1] = String("330005CBD3");
- ccheck = String("");
- pick = String("led");
- }
- void loop()
- {
- //Serial.println("hais");
- if(Serial.available() > 0)
- { // if data available from reader
- //Serial.println("hais");
- if((val = Serial.read()) == 10)
- { // check for header
- 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
- ccheck += code[bytesread];
- bytesread++; // ready to read next digit
- }
- }
- if(bytesread == 10)
- { // if 10 digit read is complete
- while(o!=2)
- {
- pick = String("led");
- pick += o;
- if(ccheck==A[0])
- {
- digitalWrite(led0,HIGH);
- }
- else if(ccheck==A[1])
- {
- digitalWrite(led1,HIGH);
- }
- o++;
- //Serial.println(ccheck);
- //Serial.println(pick);
- }
- ccheck = String("");
- o=0;
- }
- Serial.print("TAG code is: "); // possibly a good TAG
- i=0;
- while(i!=10)
- {
- Serial.print(code[i]); // print the TAG code
- i++;
- }
- i=0;
- Serial.println("");
- }
- bytesread = 0;
- delay(500); // wait for a second
- digitalWrite(led0,LOW);
- digitalWrite(led1,LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement