Note: The coding that is going to be presented is a modified version of http://www.instructables.com/id/Arduino-RC522-RFID-Door-Unlock/.
The problem with my code specifically is that i dont know if there is anyway to activate the alarm system indefinitely and disarm the system indefinitely without affecting the if else loops used for RFID communications. This is the part of the code(Look specifically where there is a while loop for mode and submode):
///////////////////////////////////////// Main Loop ///////////////////////////////////
void loop () {
do {
successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0
if (programMode) {
cycleLeds(); // Program Mode cycles through RGB waiting to read a new card
}
else {
normalModeOn(); // Normal mode, blue Power LED is on, all others are off
}
}
while (!successRead); //the program will not go further while you not get a successful read
if (programMode) {
if ( isMaster(readCard) ) { //If master card scanned again exit program mode
Serial.println(F("Master Card Scanned"));
lcd.home ();
lcd.print("--------------------");
lcd.setCursor ( 0, 1 );// go to the first line, first character
lcd.print("Master Card Scanned ");
lcd.setCursor ( 0, 2); // go to the 2nd line
lcd.print("Exiting Program Mode");
lcd.setCursor ( 0, 3);
lcd.print("--------------------");
Serial.println(F("Exiting Program Mode"));
Serial.println(F("-----------------------------"));
programMode = false;
return;
}
else {
if ( findID(readCard) ) { // If scanned card is known delete it
Serial.println(F("I know this PICC, removing..."));
deleteID(readCard);
Serial.println("-----------------------------");
}
else { // If scanned card is not known add it
Serial.println(F("I do not know this PICC, adding..."));
writeID(readCard);
Serial.println(F("-----------------------------"));
}
}
}
else {
if ( isMaster(readCard) ) { // If scanned card's ID matches Master Card's ID enter program mode
programMode = true;
Serial.println(F("Hello Master - Entered Program Mode"));
int count = EEPROM.read(0); // Read the first Byte of EEPROM that
Serial.print(F("I have ")); // stores the number of ID's in EEPROM
Serial.print(count);
Serial.print(F(" record(s) on EEPROM"));
Serial.println("");
Serial.println(F("Scan a PICC to ADD or REMOVE"));
Serial.println(F("-----------------------------"));
}
else {
Mode=0;
while(Mode==0)
{
if ( findID(readCard) ) { // If not, see if the card is in the EEPROM
Serial.println(F("Welcome, You shall pass"));
Submode=0;
INITIALISE(300); // Open the door lock for 300 ms
Mode++;
}
else { // If not, show that the ID was not valid
Serial.println(F("You shall not pass"));
denied();
}
}
while(Mode==1)
{
if ( findID(readCard) ) { // If not, see if the card is in the EEPROM
Serial.println(F("Welcome, You shall pass"));
Submode=1;
Disarm(300); // Open the door lock for 300 ms
}
else { // If not, show that the ID was not valid
Serial.println(F("You shall not pass"));
denied();
}
}
}
}
}
///////////////////////////////////////// Access Granted ///////////////////////////////////
void INITIALISE (int setDelay) {
digitalWrite(blueLed, LED_OFF); // Turn off blue LED
digitalWrite(redLed, LED_OFF); // Turn off red LED
digitalWrite(greenLed, LED_ON); // Turn on green LED
delay(1000);
lcd.home();
lcd.print("Home Security ");
lcd.setCursor ( 0, 1 ); // go to the 2nd line
lcd.print("System V1.0");
lcd.setCursor ( 0, 2 );
lcd.print("Alarm Initilized");// Hold green LED on for a second
while(Submode==0)
{
if(Sensor_Front==HIGH)
{
lcd.clear();
for(int d=0;d<15301;d+1)
{
lcd.home (); // go to the first line, first character
lcd.print("Home Security ");
lcd.setCursor ( 0, 1 ); // go to the 2nd line
lcd.print("System V1.0");
lcd.setCursor ( 0, 2 );
lcd.print("Front Comprimised");
digitalWrite(alarm, HIGH);
digitalWrite(SSR, HIGH);
delay(20);
lcd.clear();
}
}
if(Sensor_Back==HIGH)
{
lcd.clear();
for(int fade1=0;fade1<15301;fade1+1)
{
lcd.home (); // go to the first line, first character
lcd.print("Home Security ");
lcd.setCursor ( 0, 1 ); // go to the 2nd line
lcd.print("System V1.0");
lcd.setCursor ( 0, 2 );
lcd.print("Back Comprimised");
digitalWrite(alarm, HIGH);
digitalWrite(SSR, HIGH);
delay(20);
lcd.clear();
}
}
if(Sensor_Left==HIGH)
{
lcd.clear();
for(int a=0;a<15301;a+1)
{
lcd.home (); // go to the first line, first character
lcd.print("Home Security ");
lcd.setCursor ( 0, 1 ); // go to the 2nd line
lcd.print("System V1.0");
lcd.setCursor ( 0, 2 );
lcd.print("Left Comprimised");
digitalWrite(alarm, HIGH);
digitalWrite(SSR, HIGH);
delay(20);
lcd.clear();
}
}
if(Sensor_Right==HIGH)
{
lcd.clear();
for(int b=0;b<15301;b+1)
{
lcd.home (); // go to the first line, first character
lcd.print("Home Security ");
lcd.setCursor ( 0, 1 ); // go to the 2nd line
lcd.print("System V1.0");
lcd.setCursor ( 0, 2 );
lcd.print("Right Comprimised");
digitalWrite(alarm, HIGH);
digitalWrite(SSR, HIGH);
delay(20);
}
}
}
while(Submode==1)
{
lcd.home ();
lcd.print("Home Security ");
lcd.setCursor ( 0, 1 ); // go to the 2nd line
lcd.print("System V1.0");
lcd.setCursor ( 0, 2 );
lcd.print("Alarm Disarmed");
delay(5000);
lcd.clear();
}
}
///////////////////////////////////////// Access Granted(Disarm) ///////////////////////////////////
void Disarm (int setDelay) {
lcd.home ();
lcd.print("Home Security ");
lcd.setCursor ( 0, 1 ); // go to the 2nd line
lcd.print("System V1.0");
digitalWrite(blueLed, LED_OFF); // Turn off blue LED
digitalWrite(redLed, LED_OFF); // Turn off red LED
digitalWrite(greenLed, LED_ON); // Turn on green LED
delay(1000); // Hold green LED on for a second
while(Mode==1)
{
Submode=0;
Mode=0;
}
}
Thank you for any help given in advance!!