MBrendecke icon

For T2broZz

MBrendecke | PRO | 02/23/19 03:00:55 PM UTC | 0 ⭐ | 486 👁️ | Never ⏰ | []
C |

5.38 KB

|

None

|

0 👍

/

0 👎

/*
   Initial Author: ryand1011 (https://github.com/ryand1011)
 
   Reads data written by a program such as "rfid_write_personal_data.ino"
 
   See: https://github.com/miguelbalboa/rfid/tree/master/examples/rfid_write_personal_data
 
   Uses MIFARE RFID card using RFID-RC522 reader
   Uses MFRC522 - Library
   -----------------------------------------------------------------------------------------
               MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
               Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
   Signal      Pin          Pin           Pin       Pin        Pin              Pin
   -----------------------------------------------------------------------------------------
   RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
   SPI SS      SDA(SS)      10            53        D10        10               10
   SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
   SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
   SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
*/
 
#include <SPI.h>
#include <MFRC522.h>
 
#define RST_PIN         9           // Configurable, see typical pin layout above
#define SS_PIN          10          // Configurable, see typical pin layout above
 
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance
 
//________________________________________________________________________________________
char name_w[] = "a";
char yannes[] = "yannestallowitz";
char jara[] = "jaratallowitz";
int c_yannes = 0;
int c_jara = 0;
//*****************************************************************************************//
void setup() {
    Serial.begin(9600);                                           // Initialize serial communications with the PC
    SPI.begin();                                                  // Init SPI bus
    mfrc522.PCD_Init();                                              // Init MFRC522 card
    Serial.println(F("Read personal data on a MIFARE PICC:"));    //shows in serial that it is ready to read
}
 
//*****************************************************************************************//
void loop() {
 
    // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
    MFRC522::MIFARE_Key key;
    for (uint8_t i = 0; i < 6; i++) {
        key.keyByte[i] = 0xFF;
    }
 
    //some variables we need
    byte block;
    byte len;
    MFRC522::StatusCode status;
 
    //-------------------------------------------
 
    // Look for new cards
    if (!mfrc522.PICC_IsNewCardPresent()) {
        return;
    }
 
    // Select one of the cards
    if (!mfrc522.PICC_ReadCardSerial()) {
        return;
    }
 
    Serial.println(F("**Card Detected:**"));
 
    //-------------------------------------------
 
    mfrc522.PICC_DumpDetailsToSerial(&(mfrc522.uid)); //dump some details about the card
 
    //mfrc522.PICC_DumpToSerial(&(mfrc522.uid));      //uncomment this to see all blocks in hex
 
    //-------------------------------------------
 
    Serial.print(F("Name: "));
 
 
 
    block = 4;
    len = 18;
 
    //---------------------------------------- GET NAME
 
    byte buffer2[18];
    block = 1;
 
    status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 1, &key, &(mfrc522.uid)); //line 834
    if (status != MFRC522::STATUS_OK) {
        Serial.print(F("Authentication failed: "));
        Serial.println(mfrc522.GetStatusCodeName(status));
        return;
    }
 
    status = mfrc522.MIFARE_Read(block, buffer2, &len);
    if (status != MFRC522::STATUS_OK) {
        Serial.print(F("Reading failed: "));
        Serial.println(mfrc522.GetStatusCodeName(status));
        return;
    }
 
    //PRINT LAST NAME
    for (uint8_t i = 0; i < 16; i++) {
        Serial.write(buffer2[i]);
        name_w[i] = buffer2[i];
    }
    Serial.println(name_w);
 
 
    //§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§\\
  //name 1 prufen   
    for (int32_t i = 0; i < 15; i++) {
        Serial.write(name_w[i]); Serial.print("="); Serial.write(yannes[i]); Serial.println("");
 
        if (name_w[i] == yannes[i]) {
 
 
            //Serial.println("jaghjb");
            c_yannes++;
        }
 
 
        else {
            Serial.println("Nöö");
            c_yannes = 0;
 
        }
    }
    //§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§\\
    //((((((((((((((((((((((((((((((((((((((((((((((((((((\\
    //name 2 prüfen
    for (int32_t i = 0; i < 13; i++) {
        Serial.write(name_w[i]); Serial.print("="); Serial.write(jara[i]); Serial.println("");
 
        if (name_w[i] == jara[i]) {
 
 
            //Serial.println("jaghjb");
            c_jara++;
        }
        else {
            Serial.println("Nöö");
            c_jara = 0;
 
        }
    }
    //((((((((((((((((((((((((((((((((((((((((((((((((((((\\
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\\
  //ausgabe
    if (c_yannes == 15) {
        Serial.println("yannes");
        c_yannes = 0;
 
    }
    if (c_jara == 13) {
        Serial.println("jara");
        c_jara = 0;
 
    }
    else {
        Serial.println("NnnnnnnnnnnnnnnnnNNNNNNnnNNn");
    }
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\\
 
    char name_w[] = "a";
    //----------------------------------------
 
    Serial.println(F("\n**End Reading**\n"));
 
    delay(1000); //change value if you want to read cards faster
 
    mfrc522.PICC_HaltA();
    mfrc522.PCD_StopCrypto1();
}
//*****************************************************************************************//

Comments