Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. #if 0
  2. #include <SPI.h>
  3. #include <PN532_SPI.h>
  4. #include "PN532.h"
  5.  
  6. PN532_SPI pn532spi(SPI, 10);
  7. PN532 nfc(pn532spi);
  8.  
  9. /* When the number after #elif set as 1, it will be switch to HSU Mode*/
  10. #elif 0
  11. #include <PN532_HSU.h>
  12. #include <PN532.h>
  13.  
  14. PN532_HSU pn532hsu(Serial1);
  15. PN532 nfc(pn532hsu);
  16.  
  17. /* When the number after #if & #elif set as 0, it will be switch to I2C Mode*/
  18. #else
  19. #include <Wire.h>
  20. #include <PN532_I2C.h>
  21. #include <PN532.h>
  22. #include <NfcAdapter.h>
  23.  
  24. PN532_I2C pn532i2c(Wire);
  25. PN532 nfc(pn532i2c);
  26. #endif
  27.  
  28. void setup(void) {
  29. Serial.begin(115200);
  30. Serial.println("Hello!");
  31.  
  32. nfc.begin();
  33.  
  34. uint32_t versiondata = nfc.getFirmwareVersion();
  35. if (! versiondata) {
  36. Serial.print("Didn't find PN53x board");
  37. while (1); // halt
  38. }
  39.  
  40. // Got ok data, print it out!
  41. Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
  42. Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
  43. Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  44.  
  45. // Set the max number of retry attempts to read from a card
  46. // This prevents us from waiting forever for a card, which is
  47. // the default behaviour of the PN532.
  48. nfc.setPassiveActivationRetries(0xFF);
  49.  
  50. // configure board to read RFID tags
  51. nfc.SAMConfig();
  52.  
  53. Serial.println("Waiting for an ISO14443A card");
  54. }
  55.  
  56. void loop(void) {
  57. uint8_t TagUid[]={0xCE,0xA0,0x53,0x73};
  58. boolean success;
  59. uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
  60. uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
  61.  
  62. // Wait for an ISO14443A type cards (Mifare, etc.). When one is found
  63. // 'uid' will be populated with the UID, and uidLength will indicate
  64. // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  65. success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
  66.  
  67. if (success) {
  68. Serial.println("Found a card!");
  69. Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
  70. Serial.print("UID Value: ");
  71. for (uint8_t i=0; i < uidLength; i++)
  72. {
  73. Serial.print(" 0x");Serial.print(uid[i], HEX);
  74. }
  75. for (int count=0; count < uidLength; count++)
  76. {
  77. if (uid[count]==TagUid[count])
  78. {
  79. if (count == 3){ Serial.println("");
  80. Serial.println("you have a matching card");
  81. delay(1000);
  82. }
  83. }else {
  84. if (count == 3){
  85. Serial.println("");
  86. Serial.println("You have a non-matching card");
  87. delay(1000);}
  88. }
  89.  
  90. if (count==4) return;
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement