Hi there,
I have some problem with String array. My problem is I store some data from txt file to a String array, in my case CardsUIDs, and when i want to read from this array the board know he has more values on that array but he recognize just the last one. How is that working ?
When I put a card to RC522 with some UIDs what the board already know it by this array he accept only the last one.
I will post my code. So on this way I create my array with 200 max number.
String card[200];
And on this way I put values in my array on void setup() function:
while(file1.available()){
String s1=file1.readStringUntil('\n');
card[j]=s1;
j++;
}
file1.close();
And on this way I try to get the stored information from my array on void loop function. So when he get a card he will compare with datas from array:
for (l=0;l<=j;l++){
cards=card[l];
Serial.println(cards);
if( tag ==cards)
{
eng();
k=1;
SendCardID(tag,k);
}
}
And i repeat my self the program accept every time the last card number.
Oh my txt file its look like that:
Anyone know why he do that ?
I know i can't express my self on english but i dont have too much time with google translate
szilard977:
will post my code.
Let us know when you've done it
That's 1200 bytes of RAM used before you've put any data in them
So i should dont define that ? Or its too much ?
Still waiting to see your code.
But i post the most important parts of code, the all code is too much
OK.
Here is the important part of my answer:
szilard977:
l<=j
Probably oops.
No its not that, so i increment my j when i upload the uids from txt file by lines
int k = 0,oke=1,j=0,l;
String card[20],cards;
void eng();void ind();void tilt();void connectToWiFi();void SendCardID(String Card_uid, int irany);
void setup() {
Serial.begin(115200);
SPI.begin();
LittleFS.begin();
rfid.PCD_Init();
rfid.PCD_SetAntennaGain(rfid.RxGain_max);
connectToWiFi();
pinMode(relay, OUTPUT);
pinMode(LED0, OUTPUT);
pinMode(LED1, OUTPUT);
digitalWrite(relay, LOW);
File file1= LittleFS.open(filename,"r");
while(file1.available()){
String s1=file1.readStringUntil('\n');
card[j]=s1;
j++;
}
file1.close();
lcd.noBacklight(); }
void loop() {
ind();
delay(50);
if ( ! rfid.PICC_IsNewCardPresent()) {
return;
}
if ( ! rfid.PICC_ReadCardSerial()) {
return;
}
String tag ="";
for (byte i = 0; i < rfid.uid.size; ++i) {
tag += rfid.uid.uidByte[i];
}
delay(500);
delay(50);
for (l=0;l<=j;l++){
cards=card[l];
Serial.println(cards);
if( tag ==cards)
{
eng();
k=1;
SendCardID(tag,k);
}
}
szilard977:
l<=j
I'm still going with that one as being a problem
Why should be that the problem? It seems like he forgot the another values. If i modify the ```
if( tag ==cards)
{
eng();
k=1;
SendCardID(tag,k);
}
into this
if( tag ==cards)
{
eng();
k=1;
SendCardID(tag,k);
}
else
Serial.println("Hi");
The program is going in else part until, if i put the card with the last uid stored in array.
if( tag ==card[0])
{
eng();
k=1;
SendCardID(tag,k);
}
if( tag ==card[1])
{
eng();
k=1;
SendCardID(tag,k);
}
else
if( tag ==card[2])
{
eng();
k=1;
SendCardID(tag,k);
}
if( tag ==card[3])
{
eng();
k=1;
SendCardID(tag,k);
}
or this way, that is the same way with for, but same problem, he is openning the door if i give the 3rd card
system
Closed
August 29, 2022, 9:20am
13
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.