Two readers on the Australian

Asked

Viewed 108 times

0

how this code in I read the card and inform if it is registered or not. Now I need to insert two rfid readers in the Arduino. How to add the second rfid reader to this code?

include SPI.h
include MFRC522.h

define LED_VERDE 6
define LED_VERMELHO 7
define BUZZER 8
define SS_PIN 10
define RST_PIN 9

String IDtag = ""; 
bool Permitido = false;  
String TagsCadastradas[] = {"ID_1"};
MFRC522 LeitorRFID(SS_PIN, RST_PIN);

void setup() {
    Serial.begin(9600);             
    SPI.begin();                     
    LeitorRFID.PCD_Init();          
    pinMode(LED_VERDE, OUTPUT);     
    pinMode(LED_VERMELHO, OUTPUT);  
    pinMode(BUZZER, OUTPUT);        
}

void loop() {  
    Leitura();  
}
  • Possibly instantiating another object of the type MFRC522.

  • and here: Leitorrfid.Pcd_init(); would have nothing?

  • Would you have called PCD_Init from the other instance

  • According to the user Rodrigo suggested, more precise help for your problem will possibly be found in the community about Arduino.

1 answer

1


MFRC522 is a class, therefore, it is enough to instantiate two distinct objects of this class.

Instantiating:

MFRC522 LeitorRFID(SS_PIN, RST_PIN);
MFRC522 LeitorRFID2(SS_PIN, RST_PIN);

Using:

LeitorRFID.PCD_Init(); 
LeitorRFID2.PCD_Init(); 

Note that there are now two objects of the type MFRC522, a call LeitorRFID and another LeitorRFID2.

Your way of naming the variable might confuse it a bit. It would be better to name the variable by default Camel Case, because in C, C++ is usually how you do it and the Arduino language is C++. So instead of MFRC522 LeitorRFID(SS_PIN, RST_PIN); would be MFRC522 leitorRFID(SS_PIN, RST_PIN);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.