MBrendecke

For T2broZz

Feb 23rd, 2019
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.38 KB | None | 0 0
  1. /*
  2.    Initial Author: ryand1011 (https://github.com/ryand1011)
  3.  
  4.    Reads data written by a program such as "rfid_write_personal_data.ino"
  5.  
  6.    See: https://github.com/miguelbalboa/rfid/tree/master/examples/rfid_write_personal_data
  7.  
  8.    Uses MIFARE RFID card using RFID-RC522 reader
  9.    Uses MFRC522 - Library
  10.    -----------------------------------------------------------------------------------------
  11.                MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
  12.                Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
  13.    Signal      Pin          Pin           Pin       Pin        Pin              Pin
  14.    -----------------------------------------------------------------------------------------
  15.    RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
  16.    SPI SS      SDA(SS)      10            53        D10        10               10
  17.    SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
  18.    SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
  19.    SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
  20. */
  21.  
  22. #include <SPI.h>
  23. #include <MFRC522.h>
  24.  
  25. #define RST_PIN         9           // Configurable, see typical pin layout above
  26. #define SS_PIN          10          // Configurable, see typical pin layout above
  27.  
  28. MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance
  29.  
  30. //________________________________________________________________________________________
  31. char name_w[] = "a";
  32. char yannes[] = "yannestallowitz";
  33. char jara[] = "jaratallowitz";
  34. int c_yannes = 0;
  35. int c_jara = 0;
  36. //*****************************************************************************************//
  37. void setup() {
  38.     Serial.begin(9600);                                           // Initialize serial communications with the PC
  39.     SPI.begin();                                                  // Init SPI bus
  40.     mfrc522.PCD_Init();                                              // Init MFRC522 card
  41.     Serial.println(F("Read personal data on a MIFARE PICC:"));    //shows in serial that it is ready to read
  42. }
  43.  
  44. //*****************************************************************************************//
  45. void loop() {
  46.  
  47.     // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
  48.     MFRC522::MIFARE_Key key;
  49.     for (uint8_t i = 0; i < 6; i++) {
  50.         key.keyByte[i] = 0xFF;
  51.     }
  52.  
  53.     //some variables we need
  54.     byte block;
  55.     byte len;
  56.     MFRC522::StatusCode status;
  57.  
  58.     //-------------------------------------------
  59.  
  60.     // Look for new cards
  61.     if (!mfrc522.PICC_IsNewCardPresent()) {
  62.         return;
  63.     }
  64.  
  65.     // Select one of the cards
  66.     if (!mfrc522.PICC_ReadCardSerial()) {
  67.         return;
  68.     }
  69.  
  70.     Serial.println(F("**Card Detected:**"));
  71.  
  72.     //-------------------------------------------
  73.  
  74.     mfrc522.PICC_DumpDetailsToSerial(&(mfrc522.uid)); //dump some details about the card
  75.  
  76.     //mfrc522.PICC_DumpToSerial(&(mfrc522.uid));      //uncomment this to see all blocks in hex
  77.  
  78.     //-------------------------------------------
  79.  
  80.     Serial.print(F("Name: "));
  81.  
  82.  
  83.  
  84.     block = 4;
  85.     len = 18;
  86.  
  87.     //---------------------------------------- GET NAME
  88.  
  89.     byte buffer2[18];
  90.     block = 1;
  91.  
  92.     status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 1, &key, &(mfrc522.uid)); //line 834
  93.     if (status != MFRC522::STATUS_OK) {
  94.         Serial.print(F("Authentication failed: "));
  95.         Serial.println(mfrc522.GetStatusCodeName(status));
  96.         return;
  97.     }
  98.  
  99.     status = mfrc522.MIFARE_Read(block, buffer2, &len);
  100.     if (status != MFRC522::STATUS_OK) {
  101.         Serial.print(F("Reading failed: "));
  102.         Serial.println(mfrc522.GetStatusCodeName(status));
  103.         return;
  104.     }
  105.  
  106.     //PRINT LAST NAME
  107.     for (uint8_t i = 0; i < 16; i++) {
  108.         Serial.write(buffer2[i]);
  109.         name_w[i] = buffer2[i];
  110.     }
  111.     Serial.println(name_w);
  112.  
  113.  
  114.     //§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§\\
  115.   //name 1 prufen  
  116.     for (int32_t i = 0; i < 15; i++) {
  117.         Serial.write(name_w[i]); Serial.print("="); Serial.write(yannes[i]); Serial.println("");
  118.  
  119.         if (name_w[i] == yannes[i]) {
  120.  
  121.  
  122.             //Serial.println("jaghjb");
  123.             c_yannes++;
  124.         }
  125.  
  126.  
  127.         else {
  128.             Serial.println("Nöö");
  129.             c_yannes = 0;
  130.  
  131.         }
  132.     }
  133.     //§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§\\
  134.     //((((((((((((((((((((((((((((((((((((((((((((((((((((\\
  135.     //name 2 prüfen
  136.     for (int32_t i = 0; i < 13; i++) {
  137.         Serial.write(name_w[i]); Serial.print("="); Serial.write(jara[i]); Serial.println("");
  138.  
  139.         if (name_w[i] == jara[i]) {
  140.  
  141.  
  142.             //Serial.println("jaghjb");
  143.             c_jara++;
  144.         }
  145.         else {
  146.             Serial.println("Nöö");
  147.             c_jara = 0;
  148.  
  149.         }
  150.     }
  151.     //((((((((((((((((((((((((((((((((((((((((((((((((((((\\
  152.     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\\
  153.   //ausgabe
  154.     if (c_yannes == 15) {
  155.         Serial.println("yannes");
  156.         c_yannes = 0;
  157.  
  158.     }
  159.     if (c_jara == 13) {
  160.         Serial.println("jara");
  161.         c_jara = 0;
  162.  
  163.     }
  164.     else {
  165.         Serial.println("NnnnnnnnnnnnnnnnnNNNNNNnnNNn");
  166.     }
  167.     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\\
  168.  
  169.     char name_w[] = "a";
  170.     //----------------------------------------
  171.  
  172.     Serial.println(F("\n**End Reading**\n"));
  173.  
  174.     delay(1000); //change value if you want to read cards faster
  175.  
  176.     mfrc522.PICC_HaltA();
  177.     mfrc522.PCD_StopCrypto1();
  178. }
  179. //*****************************************************************************************//
Advertisement
Add Comment
Please, Sign In to add comment