Guest User

Untitled

a guest
Jun 19th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 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.   mySerial.write(0xFE);   //command flag
  17.   mySerial.write(128);    //position line 1
  18.   delay(10);  //wait 1ms
  19.   mySerial.print("RFID TOKEN = ");
  20.  
  21.   digitalWrite (13, HIGH);//onboard LED to indicate ready state
  22.   int tagString[13];
  23.   int index = 0;
  24.   boolean reading = false;
  25.  
  26.   while(Serial.available()){
  27.  
  28.     int readByte = Serial.read(); //read next available byte
  29.  
  30.     if(readByte == 2) reading = true; //begining of tag
  31.     if(readByte == 3) reading = false; //end of tag
  32.  
  33.     if(reading && readByte != 2 && readByte != 10 && readByte != 13){
  34.       //store the tag
  35.       tagString[index] = readByte;
  36.       index ++;
  37.     }
  38.  
  39.     mySerial.write(0x7c);
  40.     mySerial.write(0x1); //clear lcd
  41.  
  42.     mySerial.write(0xFE);   //command flag
  43.     mySerial.write(128);    //position line 1
  44.     delay(10);  //wait 1ms
  45.     mySerial.print("RFID TOKEN = ");
  46.     mySerial.write(0xFE);   //command flag
  47.     mySerial.write(148);    //position line 2
  48.  
  49. // debug
  50. Serial.print("number of ints in tagString: ");
  51. Serial.println(index); // should hopefully be 13 (or 12 if i'm making an off by 1 error)
  52.  
  53.     for(int x=0;x<12;x++)
  54.     {
  55.       mySerial.print (tagString[x]);//write token to lcd
  56.       Serial.println(tagString[x]);//write token to console
  57.     delay(10);
  58.     }
  59.  
  60.     // delay(10000);
  61.  
  62.  
  63.   }
  64. }
Add Comment
Please, Sign In to add comment