NFC / RFID Karte (UID) hinzufügen

Hallo,

ich habe ein Code abgeändert und würde gerne mehrere NFC / RFID Karten (UID) hinzufügen.
Leider weiß ich nicht genau was ich da eintragen muss

aktuell funktioniert der Code mit einer (1) Karte

Passage

Serial.println();  
  Serial.print("Message : ");  
  content.toUpperCase();  
  if (content.substring(1) == "D7 C4 62 C8") //change here the UID of the card/cards that you want to give access  
  {    
   Serial.println();    
     digitalWrite(LED_G, HIGH); //Green LED ON  
     s1.write(0);  
     delay(3000);  
     s1.write(180);    
     digitalWrite(LED_G, LOW);  //Green LED OFF  
     delay(3000);

This is a forum for the Fritzing application. That allows storing source code as part of the sketch, but is not really about arduino (or any other) programming. An Arduino forum would be a better choice for that information.

That said, I do program Arduino and other. Your question is really about general programming techniques, not specific to Arduino. There are several ways to do what you want. If it is only a few cards, you could just change the ‘if’ statement to use a compound condition

Dies ist ein Forum für die Fritzing-Anwendung. Das erlaubt das Speichern von Quellcode als Teil der Skizze, aber es geht nicht wirklich um Arduino (oder irgendeine andere) Programmierung. Ein Arduino-Forum wäre eine bessere Wahl für diese Informationen.

Allerdings programmiere ich Arduino und andere. Ihre Frage betrifft wirklich allgemeine Programmiertechniken, nicht spezifisch für Arduino. Es gibt mehrere Möglichkeiten, das zu tun, was Sie wollen. Wenn es sich nur um wenige Karten handelt, könnten Sie einfach die ‘if’-Anweisung ändern, um eine zusammengesetzte Bedingung zu verwenden

this_uid = content.substring(1); // just to simplify the if a little
if (this_uid == "uid 1" or this_uid == "uid 2" or this_uid == "uid 3") {
  // common code for any recognized uid
}

If there are more than a very few authorized cards, it becomes easier to create a array of the uid’s. Loop over them, to find any match.

Wenn es mehr als ein paar autorisierte Karten gibt, wird es einfacher, ein Array der UIDs zu erstellen. Schleifen Sie über sie, um eine Übereinstimmung zu finden.

const String authorized_uid[] = {
  "D7 C4 62 C8",
  "«next uid»",
  // …
};
const unsigned int authorized_count = sizeof(authorized_uid) / sizeof(String *);

bool is_authorized(String detected_uid)
{
  for (int i = 0; i < authorized_count; i++) {
    if (detected_uid == authorized_uid[i]) {
      return true;
    }
  }
  return false;
}

// …

if (is_authorized(content.substring(1))) {
  // handle authorized card
}

There are many more ways to get the same results. I used strings here. byte arrays would work as well. If different cards are supposed to do different things, a case statement would work. Or if … else if …

Es gibt viele weitere Möglichkeiten, die gleichen Ergebnisse zu erzielen. Ich habe hier Saiten verwendet. Byte-Arrays würden auch funktionieren. Wenn verschiedene Karten unterschiedliche Dinge tun sollen, würde eine Case-Anweisung funktionieren. Oder wenn … sonst wenn …