Hopefully I am just doing something really stupid but I can't get the string comparison to work. I have tried with const, define, string with and without the extra space at the end but I just can't get the first or second if to run
#include <String.h>
#include <NewSoftSerial.h>
#define enable_code "3E0018105F69 " //change this ID with your own card TAG
#define disable_code "3E00187E97CF "
NewSoftSerial RFID(2, 3);
String msg = String(60);
String ID = String(60); //string to store allowed cards
char c;
void setup()
{
Serial.begin(9600);
Serial.println("Serial Ready");
RFID.begin(9600);
Serial.println("RFID Ready");
}
void loop()
{
while(RFID.available()>0)
{
c=RFID.read();
msg += c;
Serial.println(msg); //Uncomment to view your tag ID
}
if(msg == enable_code) add();
if(msg == disable_code) del();
if(msg.length()>10) verifica();
msg="";
}
void add()
{
Serial.print("What TAG do you wanna grant access?: ");
msg="";
while(msg.length()<13)
{
while(RFID.available()>0)
{
c=RFID.read();
msg += c;
}
}
if(ID == msg)
{
Serial.println("\nAccess already granted for this card.");
msg="";
}
else
{
Serial.print("Card: ");
Serial.println(msg);
ID += msg;
ID += ",";
Serial.print("ID: ");
Serial.println(ID);
msg="";
Serial.println("Access granted for this card.");
}
}
void del()
{
msg="";
Serial.print("What TAG do you wanna deny access?: ");
while(msg.length()<13)
{
while(RFID.available()>0)
{
c=RFID.read();
msg += c;
}
}
if(ID == msg)
{
Serial.println(msg);
Serial.println("TAG found. Access for this card denied.");
//ID.replace(card,"");
int pos=ID.indexOf(msg);
msg="";
msg += (ID.substring(0,pos));
msg += (ID.substring(pos+15,ID.length()));
ID="";
ID += msg;
//Serial.print("ID: ");
//Serial.println(ID);
} else Serial.println("\nTAG not found or already denied");
msg="";
}
void verifica()
{
if(ID == msg) Serial.println("Access granted.");
else Serial.println("Access denied.");
}
I am guessing i am doing something really dumb but i have searched and searched and can't find an answer.