Hi, I was wondering if someone could help me with my code as I am new to Arduino.
I have been trying to write something to read cards and display the readings on a little lcd screen. at the moment I can only get one card reading the other cards I cannot add. I know I need to use EEPROM but I am really struggling to add the eeprom to my code , and to register different cards to my rfid. below is a code I edited from examples etc. feel free to help me out.
/* adaptado do codigo que acompanha a biblioteca MFRC522:
Este exemplo armazena o numero primeiro cartão lido em uma variavel
A partir ao aproximar um catão é feita a comparação entre o valor lido do cartão e o valor armazenado.
As informações são mostrada em um display 16x2 via comunicação I2C.
*/
// bibliotecas
#include <SPI.h> // padrão do arduino
#include <MFRC522.h> // necessário adicionar na pasta libraries do arduino
#include <Wire.h> // padrão do arduino
#include <LiquidCrystal_I2C.h> // necessário adicionar na pasta libraries do arduino
LiquidCrystal_I2C lcd(0x3F,20,4);
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // cria uma intancia MFRC522 com o nome mfrc522
int *aux;
int card1[4];
int flag = 0;
//int led = 13;
int cnt =0;
void setup() {
lcd.init();
lcd.backlight();
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
lcd.print(" Scan card");
lcd.setCursor(0,1);
lcd.print(" To Register ");
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Now a card is selected. The UID and SAK is in mfrc522.uid.
// Dump UID
for (byte i = 0; i < mfrc522.uid.size; i++) {
aux_= mfrc522.uid.uidByte*;_
_ }_
_ if(flag == 0)_
_ {_
_ lcd.clear();_
_ lcd.print(" Card UID: ");_
_ lcd.setCursor(0,1);_
_ for (byte i = 0; i < mfrc522.uid.size; i++) {_
card1 _= aux;
lcd.print( card1, DEC);
lcd.print( " ");
flag =1;
}
delay(3000);
lcd.clear();
lcd.print(" Scan card");
lcd.setCursor(0,1);
lcd.print(" To Register ");*_
* }*
* else{*
* for (byte i = 0; i < mfrc522.uid.size; i++) {*
if(aux == card1*)*
* cnt++;*
* }*
* if(cnt == mfrc522.uid.size-1)*
* {*
* lcd.clear();*
* lcd.print(" Access ");*
* lcd.setCursor(0,1);*
* lcd.print(" Allowed ");*
* delay(2000);*
* }*
* else*
* {*
* lcd.clear();*
* lcd.print(" access ");*
* lcd.setCursor(0,1);*
* lcd.print(" reject ");*
* delay(2000);*
* }*
* }*
* lcd.clear();*
* lcd.print(" Scan card");*
* lcd.setCursor(0,1);*
* lcd.print(" To Access ");*
* cnt=0;*
}