Guest User

Untitled

a guest
Jun 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2. SoftwareSerial mySerial(9, 10);            // mySerial(rx, tx);
  3.  
  4.  
  5. char val=0;
  6.  
  7. void setup()
  8. {
  9.   Serial.begin(9600);
  10.   mySerial.begin(9600);
  11. }
  12.  
  13.  
  14.  
  15. void loop(){
  16.  
  17.   digitalWrite (13, HIGH);//onboard LED to indicate ready state
  18.   char tagString[13];
  19.   int index = 0;
  20.   boolean reading = false;
  21.  
  22.   while(Serial.available()){
  23.  
  24.     int readByte = Serial.read(); //read next available byte
  25.  
  26.     if(readByte == 2) reading = true; //begining of tag
  27.     if(readByte == 3) reading = false; //end of tag
  28.  
  29.     if(reading && readByte != 2 && readByte != 10 && readByte != 13){
  30.       //store the tag
  31.       tagString[index] = readByte;
  32.       index ++;
  33.       if(index==12){
  34.         mySerial.write(0x7c);
  35.         mySerial.write(0x1); //clear lcd
  36.  
  37.         mySerial.write(0xFE);   //command flag
  38.         mySerial.write(128);    //position line 1
  39.         delay(10);  //wait 1ms
  40.         mySerial.write("RFID TOKEN = ");
  41.         mySerial.write(0xFE);   //command flag
  42.         mySerial.write(148);    //position line 2
  43.         for(int x=0;x<12;x++)
  44.         {
  45.           mySerial.print (tagString[x]);//write token to lcd
  46.           Serial.print(val);//write token to console
  47.         }
  48.       }
  49.     }
  50.  
  51.  
  52.     // delay(10000);
  53.  
  54.  
  55.   }
  56. }
Add Comment
Please, Sign In to add comment