Do i need a else if statement for the if, below for in the loop?
Rearranged code still with no luck.
Regards
#include <SPI.h>
#include <MFRC522.h>
constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above
constexpr uint8_t SS_1_PIN = 10; // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
constexpr uint8_t SS_2_PIN = 8; // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1
constexpr uint8_t NR_OF_READERS = 2;
byte ssPins[] = {SS_1_PIN, SS_2_PIN};
MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
//*****************************************************************************************//
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
Serial.print(F("Reader "));
Serial.print(reader);
Serial.print(F(": "));
mfrc522[reader].PCD_DumpVersionToSerial();
}
}
uint8_t control = 0x00;
//*****************************************************************************************//
void loop() {
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
// Look for new cards
if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
Serial.println(reader); {
if (reader == 0) {
Serial.println("NewCard ");
while (1) {
control = 0;
for (int i = 0; i < 3; i++) {
if (!mfrc522[reader].PICC_IsNewCardPresent()) {
if (mfrc522[reader].PICC_ReadCardSerial()) {
//Serial.print('a');
control |= 0x16;
}
if (mfrc522[reader].PICC_ReadCardSerial()) {
//Serial.print('b');
control |= 0x16;
}
//Serial.print('c');
control += 0x1;
}
//Serial.print('d');
control += 0x4;
}
//Serial.println(control);
if (control == 13 || control == 14) {
//card is still there
} else {
break;
}
}
Serial.println("CardRemoved");
delay(500); //change value if you want to read cards faster
}
else if (reader == 1) {
Serial.println("NewCard ");
while (1) {
control = 0;
for (int i = 0; i < 3; i++) {
if (!mfrc522[reader].PICC_IsNewCardPresent()) {
if (mfrc522[reader].PICC_ReadCardSerial()) {
//Serial.print('a');
control |= 0x16;
}
if (mfrc522[reader].PICC_ReadCardSerial()) {
//Serial.print('b');
control |= 0x16;
}
//Serial.print('c');
control += 0x1;
}
//Serial.print('d');
control += 0x4;
}
//Serial.println(control);
if (control == 13 || control == 14) {
//card is still there
} else {
break;
}
}
Serial.println("CardRemoved");
delay(500); //change value if you want to read cards faster
}
mfrc522[reader].PICC_HaltA();
mfrc522[reader].PCD_StopCrypto1();
}
}
}
}
//*****************************************************************************************//a