Guest User

Untitled

a guest
Jan 10th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1.  
  2. #include <DigitalToggle.h>
  3. #include <MFRC522.h>
  4. #include <SPI.h> // Used for communication via SPI with the Module
  5.  
  6. // WS2812 RGB Stick connection
  7. #define LedPin 7 // Pin 5 connected to DIN of RGB Stick
  8.  
  9. #define SDAPIN 10 // RFID Module SDA Pin is connected to the UNO 10 Pin
  10. #define RESETPIN 8 // RFID Module RST Pin is connected to the UNO 8 Pin
  11.  
  12. byte onOff; //SE HER
  13. byte FoundTag; // Variable used to check if Tag was found
  14. byte ReadTag; // Variable used to store anti-collision value to read Tag information
  15. byte TagData[MAX_LEN]; // Variable used to store Full Tag Data
  16. byte TagSerialNumber[5]; // Variable used to store only Tag Serial Number
  17. byte GoodTagSerialNumber[5] = {0x76, 0xD6, 0x12, 0x7E}; // The Tag Serial number we are looking for
  18. MFRC522 nfc(SDAPIN, RESETPIN); // Init of the library using the UNO pins declared above
  19.  
  20. void setup() {
  21. pinMode(LedPin, OUTPUT);
  22. digitalWrite(LedPin, LOW);
  23. SPI.begin();
  24. Serial.begin(115200);
  25. onOff = 0;
  26.  
  27. // Start to find an RFID Module
  28. Serial.println("Looking for RFID Reader");
  29. nfc.begin();
  30. byte version = nfc.getFirmwareVersion(); // Variable to store Firmware version of the Module
  31.  
  32. // If can't find an RFID Module
  33. if (! version) {
  34. Serial.print("Didn't find RC522 board.");
  35. while (1); //Wait until a RFID Module is found
  36. }
  37.  
  38. // If found, print the information about the RFID Module
  39. Serial.print("Found chip RC522 ");
  40. Serial.print("Firmware version: 0x");
  41. Serial.println(version, HEX);
  42. Serial.println();
  43. }
  44.  
  45. void loop() {
  46. String GoodTag = "False"; // Variable used to confirm good Tag Detected
  47.  
  48. // Check to see if a Tag was detected
  49. // If yes, then the variable FoundTag will contain "MI_OK"
  50. FoundTag = nfc.requestTag(MF1_REQIDL, TagData);
  51.  
  52. if (FoundTag == MI_OK) {
  53. delay(200);
  54.  
  55. // Get anti-collision value to properly read information from the Tag
  56. ReadTag = nfc.antiCollision(TagData);
  57. memcpy(TagSerialNumber, TagData, 4); // Write the Tag information in the TagSerialNumber variable
  58.  
  59. Serial.println("Tag detected.");
  60. Serial.print("Serial Number: ");
  61. for (int i = 0; i < 4; i++) { // Loop to print serial number to serial monitor
  62. Serial.print(TagSerialNumber[i], HEX);
  63. Serial.print(", ");
  64. }
  65. Serial.println("");
  66. Serial.println();
  67.  
  68.  
  69. // Check if detected Tag has the right Serial number we are looking for
  70. for (int i = 0; i < 4; i++) {
  71. if (GoodTagSerialNumber[i] != TagSerialNumber[i]) {
  72. break; // if not equal, then break out of the "for" loop
  73. }
  74. if (i == 3) { // if we made it to 4 loops then the Tag Serial numbers are matching
  75. GoodTag = "TRUE";
  76. }
  77. }
  78. if (GoodTag == "TRUE") {
  79. Serial.println("Success!!!!!!!");
  80. Serial.println();
  81. onOff=!onOff ; //her skiftes status mellem on og off
  82. digitalWrite(LedPin,onOff);
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment