Good I have this code and I would like to find a way for the incoming cards to be blocked this is only to give the green light just one time
#include <SD.h>
File myFile;
#include <SPI.h>
#include <MFRC522.h>
#include <Adafruit_NeoPixel.h>
#include "hsv.h"
// data pin
#define PIN 6
// led count
#define CNT 24
// max Hue
#define MAXHUE 256*6
MFRC522 mfrc522(10, 9);
int x = 0;
byte sel = 0;
byte c1 = 0;
byte c2 = 0;
byte c3 = 0;
String Status = "";
String cconteudo = "";
String usuario = "";
String nome = "";
char caractere;
char carac;
int position = 0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(CNT, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600);
strip.begin();
strip.clear();
strip.show();
SPI.begin();
if (SD.begin(4)) {
myFile = SD.open("rfid.txt");
//FAZ A CONTAGEM DOS USUÃRIOS CADASTRADOS/NÚMERO DE LINHAS NO BANCO
if (myFile) {
while (myFile.available()) {
for (x; myFile.read() == 13; x++) {
delay(10);
}
}
}
else {
Serial.println("Falha ao abrir banco de dados");
}
Serial.print(x);
Serial.println(" usuarios cadastrados: ");
myFile.close();
!SD.begin(4);
}
}
void loop() {
sel = 0;
mfrc522.PCD_Init();
while (sel == 0) {
Serial.println("Aproxime o seu cartao do leitor...");
cconteudo = "";
while ( ! mfrc522.PICC_IsNewCardPresent()) {
//LIGA LED AZUL DE ESPERA
for (int i = 0; i < CNT; i++)
strip.setPixelColor((i + position) % CNT, getPixelColorHsv(i, 1000, 255, strip.gamma8(i * (200 / CNT))));
strip.show();
position++;
position %= CNT;
delay(10);
//LIGA LED AZUL DE ESPERA
}
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
for (byte i = 0; i < mfrc522.uid.size; i++) {
cconteudo.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
cconteudo.concat(String(mfrc522.uid.uidByte[i], HEX));
}
cconteudo.toUpperCase();
cconteudo.trim();
mfrc522.PICC_HaltA();
myFile = SD.open("rfid.txt");
if (myFile) {
while (myFile.available() && (c2 == 0)) {
caractere = 0;
while (myFile.available() && (caractere != ';') && (caractere != 13) && (c1 == 0)) {
caractere = myFile.read();
if ((caractere != ';') && (caractere != 13)) {
usuario.concat(caractere);
}
}
usuario.trim();
if ((cconteudo == usuario ) && (c1 == 0) ) {
Status = "Usuario encontrado";
//LIGA LED VERDE DE ACESSO AUTORIZADO
for(byte x=0;x<24;x++)
{
strip.setPixelColor(x,0, 255, 0);
}
strip.show();
delay(2000);
strip.clear();
strip.show();
//LIGA LED VERDE DE ACESSO AUTORIZADO
Serial.println(Status);
c1 = 1;
c3 = 1;
}
else {
usuario = "";
Status = "Usuario nao encontrado ";
}
if (c3 == 1) {
carac = 0;
while (myFile.available() && (carac != 13) && (c3 == 1)) {
carac = myFile.read();
if ((carac != 13) && (carac != ';')) {
nome.concat(carac);
}
delay(10);
}
nome.trim();
if (c3 == 1) {
c3 = 0;
c2 = 1;
sel = 1;
}
}
}
}
else {
Serial.println("Falha ao abrir banco de dados");
}
if (Status != "Usuario encontrado") {
//LIGA LED VERMELHO DE ACESSO NEGADO
for(byte x=0;x<24;x++)
{
strip.setPixelColor(x,255, 0, 0);
}
strip.show();
delay(2000);
strip.clear();
strip.show();
//LIGA LED VERMELHO DE ACESSO NEGADO
Serial.println(Status);
}
}
myFile.close();
Serial.print("Bem vindo ");
Serial.println(nome);
delay(2000);
x = 0;
sel = 0;
c1 = 0;
c2 = 0;
c3 = 0;
Status = "";
cconteudo = "";
usuario = "";
nome = "";
caractere = '0';
carac = '0';
}