Hi Everyone!
I am working on a code to control an automated door and want to allow multiple users access while denying others. I also want to be showing messages on the serial monitor each time to confirm functionality and be able to add different LEDs to turn on and off. I have the following code that works but do not know how to add the items in the /* comment section*/ when added I continue to get "tag has failed".
Thoughts?
Thanks!
void setup()
{
Serial.begin(9600);
}
// Global variables -- don't get destroyed
byte goodcode[12] = {
52, 49, 48, 48, 51, 68, 54, 65, 68, 55, 67, 49};
byte humancode[12] = {
51, 68, 48, 48, 52, 53, 69, 52, 49, 53, 56, 57};
int x = 0;
int human;
int dog;
boolean GOOD = 0;
void loop()
{
byte c;
// IF NORMAL SERIAL IS AVAILABLE
if(Serial.available())
{
c = Serial.read();
// The RFID reader sends a "2" for a new tag.
// This code resets everything
if(c == 2)
{
// Add code for the start of a new
x = 0;
GOOD = true;
}
// If the RFID tag reads in anything other than a new tag
// Or end of the tag
else if (c != 3)
{
// This code is for troubleshooting
Serial.print("Comparing ");
Serial.print(c);
Serial.print(" to ");
Serial.print(goodcode[x]);
Serial.print(" for an x value of ");
Serial.println(x);
// Compares the current byte to what we want
if(c == goodcode[x])
{dog = 1;
//STILL GOOD
}
/////////////////////////////////////////////////////////
/* TRYING TO ADD FUNTION THAT FOLLOWS THE FOLLOWING LOGIC
if(c == humancode[x])
{human = 1;
//STILL GOOD
}
*/
/////////////////////////////////////////////////////////
else
{
// Tag has failed
GOOD = false;
}
//Whether it fails or not, increment x
x++;
}
// Code executes when a "3" is sent (end of RFID)
else
{
if(GOOD && (dog == 1))
{
// Tag is good
Serial.println("DogTag has passed");
}
/////////////////////////////////////////////////////////////
/*
if(GOOD && (human == 1))
{
// Tag is good
Serial.println("HumanTag has passed");
}
*/
///////////////////////////////////////////////////////////
else
{
// Tag is bad
Serial.println("Tag has failed");
}
}
//Serial.println(c);
}
}