From b668d244b69d14389458fa41e00ad8b34166b1fb Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Sun, 27 Nov 2011 22:37:23 -0700 Subject: [PATCH] Cleanup --- Open_Access_Control/Open_Access_Control.pde | 24 ++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Open_Access_Control/Open_Access_Control.pde b/Open_Access_Control/Open_Access_Control.pde index abb5fd9..1f78d6e 100644 --- a/Open_Access_Control/Open_Access_Control.pde +++ b/Open_Access_Control/Open_Access_Control.pde @@ -64,7 +64,7 @@ byte reader1Pins[]={2,3}; // Reader 1 pins const byte relayPins[]= {6,7,8,9}; // Relay output pins // statics -#define RELAYDELAY 18000 // How long to open door lock once access is granted. (1000 = 1sec) +#define RELAYDELAY 1800000 // How long to open door lock once access is granted. (1000 = 1sec) #define RELAYPIN1 relayPins[0] // Define the pin for electrified door 1 hardware #define RELAYPIN2 relayPins[2] // Define the pin for electrified door 2 hardware @@ -216,17 +216,21 @@ void loop() // Main branch, runs over and ov ////////////////////////// // check timer -- if expired, remove authorization - long currentTime = millis() - relay1timer; - if(currentTime >= RELAYDELAY) { - authorized = false; - } - - long remaining = (RELAYDELAY - currentTime) / 1000; - long secRemaining = (RELAYDELAY - currentTime) / 1000 % 60; - long minRemaining = (RELAYDELAY - currentTime) / 1000 / 60 % 60; - long hrsRemaining = (RELAYDELAY - currentTime) / 1000 / 60 / 60; if(authorized && relay1high) { + // calculate current time elapsed + long currentTime = millis() - relay1timer; + // if time entirely elapsed, deauthorize. + if(currentTime >= RELAYDELAY) { + authorized = false; + } + + // calculate for display + long remaining = (RELAYDELAY - currentTime) / 1000; + long secRemaining = (RELAYDELAY - currentTime) / 1000 % 60; + long minRemaining = (RELAYDELAY - currentTime) / 1000 / 60 % 60; + long hrsRemaining = (RELAYDELAY - currentTime) / 1000 / 60 / 60; + // display timer & username Serial.print(hrsRemaining); Serial.print(":");