how to program led in condition

Dear friends, Help.

I have a program sending messages to serial port from rfid 522.
Each rfid has a key.

d8864670

How to program a led while reader detects a card?

#include <MFRC522.h>
#include <SPI.h>

byte nfc[21] = {12, 11, 10, 9, 8, 7, 6, 4, 3, 2, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32};
MFRC522 *mfrc522[21];

void setup() {
  for (byte i = 0; i < 21; i++) mfrc522[i] = new MFRC522 (nfc[i], 5);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  for (byte i = 0; i < 21; i++) mfrc522[i]->PCD_Init();
  for (byte i = 0; i < 21; i++) pinMode(nfc[i], OUTPUT);
   Serial.begin(9600);
  Serial.println("Ready to scan");
}

void loop() {
  for (byte i = 0; i < 21; i++) {
    read32bitValue(0, nfc[i]);
    readCard(*mfrc522[i], i);
  }
}


void read32bitValue(int value, int ss) {
  digitalWrite(ss, LOW);
  uint32_t val;
  val = SPI.transfer(0xff); //0xff is a dummy
  val |= (uint32_t)SPI.transfer(0xff) << 8;
  val |= (uint32_t)SPI.transfer(0xff) << 16;
  val |= (uint32_t)SPI.transfer(0xff) << 24;
  digitalWrite(ss, HIGH); 
}

// Get the UID of the card being scanned
String getID(MFRC522 card) {
  String output = "";
  for (byte i = 0; i < card.uid.size; i++) {
    output += card.uid.uidByte[i] < 0x10 ? "0" : "";
    output += String(card.uid.uidByte[i], HEX);
  }
  return output;
}

void readCard(MFRC522 card, int readerNumber) {
  if ( !card.PICC_IsNewCardPresent()) {
    return;
  }
  if ( !card.PICC_ReadCardSerial()) {
    return;
  }
  Serial.print("Card " + String(readerNumber) + ":");
  Serial.println(getID(card));
}
if(cardDetect){
  digitalWrite(LedPin, HIGH);
}
[code]

Or what exactly is the problem? Where are you stuck?

Each card has a key b8755439. How to initialize a key. and if the right key - blink LED?

Thanks.

Or what exactly is the problem? Where are you stuck?

He has a problem; he does not exactly know where it could be. If he could pin-point the problem, he could certainly solve it. The experienced people are in the Forum to hear them!

MFRC522 *mfrc522[21];

Why do you have an array of pointers? Do you have 21 of these devices connected to one Arduino?

  read32bitValue(0, nfc[i]);

What is the point of calling this function? It accomplishes NOTHING useful.

Serial.print("Card " + String(readerNumber) + ":");

Lazy f**k.

How to program a led while reader detects a card?

Well, first, you get a programmable LED. I've never heard of one, so you might have a difficult time.

This forum, though, is about programming the Arduino, not programming toaster ovens and beer brewing equipment.

If you have some issues with programming the Arduino, feel free to ask them here.

Yes I have 21 readers and 21 leds. How to turn leds ON while reader detects a card with ID b9119293.

How to turn leds ON while reader detects a card with ID b9119293.

While? How long do you think it takes the reader to detect a specific card?

Did you mean when?

Do you care which reader detects the card?

Is b9119293 a series of hex values stupidly jammed together? A binary value from some planet where binary means 10? A string that you forgot to put in quotes?

Is the LED to come on only for that specific card? When should it go off?

Reader detects a card with delay 3-5 seconds.

Yes, when the reader detects specified card it turns specified led On.

Thanks

Why on earth do you have one Arduino with 21 readers :o

A mystery

humapoc: Reader detects a card with delay 3-5 seconds.

Yes, when the reader detects specified card it turns specified led On.

Thanks

9 questions, 2 answers is the wrong ratio.