This has to do with the exit button/relay. I call these functions from elsewhere, but basically it sets the timeout for activating the exit relay. I also use this as a timeout to enter commands to the system (enter or leave modes, like adding users)
//exit button stuff
const int exit_button = 48; //digital pin the exit button is attached to
const int exit_relay = 0; //relay the door solenoid is on
const unsigned long exit_time = 3000; //time to keep the door open in thousandths of a second
boolean exiting = 0; //whether or not the door should be open (and timer running)
unsigned long exit_start_time = 0; //used for count down timer
That is the initialization; sets the button, relay, timeout, and two variables so it can let the rest of the code execute while it’s open.
logging(” – “);
loggingln(“exit relay open”);
exiting = 1;
exit_start_time = current_time;
That starts the ‘exiting’ procedure, starts the timer rolling and opens the door.
logging(” – “);
loggingln(“exit relay closed”);
exiting = 0; //no longer in exiting mode
//exit_start_time = 0; //not needed
digitalWrite(relaysToPins[exit_relay], LOW); //close door
That stops the exit procedure, pretty simple really.
if (!digitalRead(exit_button)) //exit button pressed
That checks to see if the exit button was pressed, and starts the exit procedure.
if (current_time – exit_start_time > exit_time) //exit time out loop
That checks to see if the door should be re-locked (you can of course extend the timer with more code that backs up the start time to cheat this check)
That’s all there is to the exit button and exit relay code. It can also be called like any other relay from the I/O section, but it operates on its own unlike the others. This is part of the OpenAccess project.