Hallo, ich habe im Internet zu dem RFID Modul ein Beispiel Code gefunden und benutzt, weil ich das selber nicht hinbekommen habe. Aber ich will den Code auch verstehen. Was macht :
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
und
Serial.print(mfrc522.uid.uidByte < 0x10 ? " 0" : " ");
_ Serial.print(mfrc522.uid.uidByte*, HEX);_
_ content.concat(String(mfrc522.uid.uidByte < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte, HEX));
Hier der ganze Code:
```_
#include <SPI.h>
#include <MFRC522.h>
const int SdaPin = 10; // SDA an Pin 10 (bei MEGA anders)
const int RstPin = 9; // RST an Pin 9 (bei MEGA anders)
MFRC522 mfrc522(SdaPin, RstPin); // Create MFRC522 instance.
const int GreenLedPin = 7;
const int RedLedPin = 8;
void setup()
{
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.println("Approximate your card to the reader...");
Serial.println();
pinMode(GreenLedPin, OUTPUT);
pinMode(RedLedPin, OUTPUT);
}
void loop()
{
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if (content.substring(1) == "D2 40 DE C3")
{
Serial.println("Authorized access");
Serial.println();
digitalWrite(GreenLedPin, HIGH);
delay(1000);
digitalWrite(GreenLedPin, LOW);
}
else {
Serial.println(" Access denied");
digitalWrite(RedLedPin, HIGH);
delay(1000);
digitalWrite(RedLedPin, LOW);
}
}
_```*_