Two readers on arduino

0

As this code I read the card and inform if it is registered or not. Now I need to insert two rfid readers into the Arduino. How to add the second rfid reader in 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();  
}
    
asked by anonymous 17.03.2017 / 10:42

1 answer

1

MFRC522 is a class , so just instantiate two distinct objects from this class 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 type MFRC522 , one called LeitorRFID and another LeitorRFID2 .

Your way of naming the variable may be confusing. It would be best to name the variable following the pattern Camel Case , because in C, C ++ is usually how you do it and the language of Arduino is C ++. So, instead of MFRC522 LeitorRFID(SS_PIN, RST_PIN); would be MFRC522 leitorRFID(SS_PIN, RST_PIN);

    
21.03.2017 / 14:56