Advertisement
Guest User

parallax

a guest
Jul 1st, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. int val = 0;
  2. char code[10];
  3. int bytesread = 0;
  4.  
  5. void setup() {
  6.  
  7. Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
  8. pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
  9. digitalWrite(2, LOW); // Activate the RFID reader
  10.  
  11. }
  12.  
  13.  
  14. void loop() {
  15.  
  16. if(Serial.available() > 0)
  17. { // if data available from reader
  18. Serial.println ("Serial.available");
  19. if((val = Serial.read()) == 10) { // check for header
  20. bytesread = 0;
  21. Serial.println (val);
  22. while(bytesread<10) { // read 10 digit code
  23. if( Serial.available() > 0) {
  24. val = Serial.read();
  25. if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
  26. break; // stop reading
  27. }
  28. code[bytesread] = val; // add the digit
  29. bytesread++; // ready to read next digit
  30. }
  31. }
  32. if(bytesread == 10) { // if 10 digit read is complete
  33. Serial.print("TAG code is: "); // possibly a good TAG
  34. Serial.println(code); // print the TAG code
  35. }
  36. bytesread = 0;
  37. digitalWrite(2, HIGH); // deactivate the RFID reader for a moment so it will not flood
  38. delay(1000); // wait for a bit
  39. digitalWrite(2, LOW); // Activate the RFID reader
  40. Serial.println ("done reading");
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement